Questions tagged [javascript]

JavaScript (not to be confused with Java) is a high-level, dynamic, multi-paradigm, weakly-typed language used for both client-side and server-side scripting. Use this tag for questions regarding common implementations of ECMAScript, JavaScript, JScript, etc. JS does not typically refer to its ECMA-cousin, ActionScript.

Filter by
Sorted by
Tagged with
-3 votes
1 answer
47 views

Testing a React component which receives a function as a prop

Suppose there's a root <App /> which houses multiple components, one of them being, say <SearchBox />. App component houses the app state (such as searchResults array) and iterates the ...
user avatar
  • 75
6 votes
1 answer
605 views

Should published npm packages target ES5 syntax?

A bit of background: I've been using Webpack with babel-loader for a while and overall the experience has been hugely positive. Yesterday, I published an npm package of my own (to a private registry), ...
user avatar
  • 660
4 votes
3 answers
613 views

Is this extensive usage of closure a known (anti-)pattern? And does it have a name?

I often use function closures for storing data (e.g. database URL), which doesn't change between function calls. Is this an (anti-)pattern? Does it have a name? While developing apps, which recieve ...
user avatar
2 votes
2 answers
233 views

How do modern JS engines terminate unresponsive scripts?

I'm trying to implement a safety feature that puts a timeout around a huge function call. Pretty simple, I thought, but it turned out much harder than expected; there's no built-ins for this in any of ...
user avatar
16 votes
10 answers
6k views

Are immutable objects important only in multi-threaded applications and if so, how are shared immutable objects useful?

I think the answer to the first part of my question is, "yes" -- no point in making objects immutable in a single-threaded application (or I guess in a multi-threaded application if that ...
user avatar
  • 517
1 vote
2 answers
85 views

How can I cleanly set up debug logging in my javascript frontend?

I basically want to be able to "turn on debug logging" like you can do with many applications that run in a shell. The naive way of implementing it would be to insert a statement like this ...
user avatar
0 votes
1 answer
85 views

How to add event handlers to an object containing elements

I am new to JavaScript, I've done most of my coding in Python, and haven't found a clear answer to this question. If I have an object containing element ids and function parameters, and I want to add ...
user avatar
2 votes
1 answer
1k views

Digital Signature for PDF files through Web Application

We are developing a Web Application for manage dental clinics. The app can generate PDF files through the PHP backend (for example invoices, quotes etc.). Each of those PDF file needs to be digitally ...
user avatar
  • 25
-1 votes
1 answer
261 views

Is async/await a good alternative for locks in JavaScript?

Yes, I know, the question title is a bit provocatory. But let me explain. I needed to execute a sequence of async tasks in JavaScript. They are async because I need them to be non-blocking, but I ...
user avatar
23 votes
8 answers
11k views

Can I use additional parameters in recursion problems?

Okay, I was being interviewed at a company and the interviewer asked me a recursion problem. It was an online interview, so, he had set up the problem statement and a function signature on CodeSandbox ...
user avatar
3 votes
2 answers
240 views

What is the rationale for making certain methods for data types static?

In C#, for instance, there are static methods for telling if a string is null or empty, finding an element in an array, clearing an array, etc. However there's an instance method for replacing ...
user avatar
  • 587
1 vote
1 answer
91 views

How to manage 2 libraries that do mostly the same things in a project?

I am encountering a design problem on a new project. I have chosen the library Luxon (https://moment.github.io/luxon/) because I think it suits this project perfectly. Date-fns (https://date-fns.org/) ...
user avatar
0 votes
0 answers
85 views

Does v8 have nested stack frames?

In chapter 4 of the Zone JS primer the following is mentioned: So far, we have discussed how zones are created, forked and how they maintain their state across asynchronous operations. Zones are ...
user avatar
  • 177
0 votes
1 answer
82 views

Is there a way I can make something happen on my nodejs server at a particular time

I'm not sure that I'm even asking the right question so I hope you guys can point me in the right direction here. I have a full stack web app which has listings (think eBay, Gumtree, Craigslist) and I ...
user avatar
0 votes
1 answer
116 views

Use nullable or undefineable as object type?

This come with a debate with my colleague that I'm using nullable object type. type Value = Node | null const [v0, setV0] = React.useState<Value>(null) const [v1, setV1] = React.useState&...
user avatar
  • 539
22 votes
8 answers
7k views

Should child nodes have a reference to their parents?

Let's say you are engineering a chat room software. let client = new Client(); let room = rooms.FindRoom(); room.addClient(client); This room (parent) now has a client (child). client.on('message', (...
user avatar
-1 votes
1 answer
66 views

Mutexes at application logic level

In my node.js app I have a async function that fetches remote documents and caches them on the disk. Upon a retrieval request for a document first checks the disk, if found loads it from the disk ...
user avatar
  • 193
-2 votes
1 answer
92 views

How to start developing a well architected Javascript Library?

I want to start developing an. open-source javascript library. I can see other open-source libraries are well structured. They have src, dist, test kind of folders, etc. Which is making me very ...
user avatar
0 votes
0 answers
84 views

Is XSS by html event injection a problem in this client-side sanitization?

I'm making my own client-side router which dynamically requests html pages from Firebase hosting, and the website uses Cloud Firestore with secure rules. Is there any XSS HTML event js injection ...
user avatar
-3 votes
2 answers
960 views

Should I use Flask w/ Javascript OR a Javascript UI that calls a Flask / Connexion API?

I recently wrote a data management tool in Python & SQLAlchemy. Now, I need to put a web UI on it. While I want to start small, there is some need for interactivity, like drag and drop in tables, ...
user avatar
  • 103
-3 votes
1 answer
75 views

Might be inheriting a php spagetti project. Full rewrite in different tech stack? [duplicate]

I'm in dire need of some help. My background is from python, js and ruby, with using frameworks to provide good structure. A potential client has an internal app which does quite a bit of stuff. This ...
user avatar
2 votes
4 answers
288 views

What prevented compiled languages from being adopted on the web originally, as opposed to JavaScript?

Since my previous question was closed (https://stackoverflow.com/q/62354455/1173166), I thought this would be a better place to ask the question. Original: JavaScript we designed specifically for ...
user avatar
  • 153
-3 votes
1 answer
55 views

Does using a destructured object as function arguments make sense?

Once upon a time we did this /** * Function that does lots of things * @param {boolean} state * @param {number} max * @param {string} set * @param {number} timeout * @param {boolean} bail * @...
user avatar
11 votes
7 answers
2k views

Should you make use of 'accidental polymorphism'?

Sometimes I find myself in situations where just by happenstance two things can be treated the same way. But they aren't truly the same, it's just coincedence. Let me give an example, imagine we are ...
user avatar
0 votes
2 answers
2k views

How to handle different types of errors in Clean Architecture?

So, in the process of creating a user there are 4 possible outcomes: Username is already taken Email is already taken Username is invalid Email is invalid Here is what I have in the controller for ...
user avatar
  • 668
-4 votes
1 answer
64 views

Message Strings in Backend

Its ok to have hardcoded strings on backend? Example: Log.e("Error connecting to the database") The text "Error connecting to the database" should be hardcoded there? Or should it be in a separated ...
user avatar
1 vote
2 answers
133 views

Where should I put the .scss files in the scaffold?

I have developed an open-source vue.js scaffold which is based on my exprience and study on various vuejs projects. Currently it has a good structure(i think), but i'm nervous about is it good ...
user avatar
-1 votes
1 answer
89 views

Good representation for list of items that can be grouped together

I am building the frontend of a web app in JavaScript that manages list of past events. It basically has the following requirements: Events are displayed in a vertical list. Events can be moved to ...
user avatar
  • 143
-3 votes
1 answer
56 views

Do I need MongoDB (or another type of database) to authenticate with Google?

I'm creating a web application using Node.js and Pug, and have recently been looking at adding external OAuth authentication to this site, using Express and Passport.js. I've found a lot of examples ...
user avatar
  • 113
-2 votes
1 answer
63 views

Is there a less complicated alternative to handling this simple mySQL query in Node?

To Put My Question In Better Context... I am about done writing my first real-world Node application, which would be classified as a REST API. For myself, it was a bit challenging to wrap my head ...
user avatar
  • 99
1 vote
2 answers
52 views

Suitable way to round results returned by any function of a class

Assume there is a class Shape. The class has two functions area() and perimeter(). Let's say Circle and Square inherit from Shape and override these methods. Obviously the results are going to be ...
user avatar
-4 votes
1 answer
223 views

Best way to structure reusable code using Node.JS, EJS, and front end JS?

I'm more or less learning the MEAN stack (have yet to start on Angular, so currently using straight vanilla JS for front-end) and part of what I'm building for my portfolio is a drag-and-drop form ...
user avatar
-3 votes
4 answers
904 views

Is it possible to prevent tech scammers from editing bank webpages?

In a refund tech scam, tech scammers use Chrome Developer Tools to edit the HTML directly on the victim's bank webpage through a Remote Desktop (Teamviewer, AnyDesk, etc) to fool their victim into ...
user avatar
3 votes
1 answer
189 views

What is the expected performance of While loops using `array.pop()` assignment vs other methods

Recently I was asked to refactor some code that leverages JavaScript's array.reduce() method because other developers felt the code hard to read. While doing this I decided to play around with some ...
user avatar
0 votes
3 answers
213 views

React - When is a backend necessary?

So I'm currently playing around with web development as a project, and I've been looking at React recently. My current issue is that I'm having trouble distinguishing between front and back end ...
user avatar
-2 votes
1 answer
169 views

Is frequent use of bind(this) in Javascript a code smell?

I am doing a project for a client where I am getting my first real heavy, hands-on exposure with Javascript. Since I have learned about adding .bind(this to callback functions, I find I am doing it ...
user avatar
-2 votes
3 answers
70 views

Is there a secure way to ensure a data in an API endpoint of mine came from an Instagram endpoint?

Is there a way through encryption/keys/jwt or anything else to ensure that the data being sent through a POST request is only data coming from another request I made on the client to a 3rd party ...
user avatar
  • 219
-4 votes
4 answers
328 views

What are use cases of using optional for loop statements?

I don't think any of them are good practice. In addition to that they make the code longer. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for Optional initialization ...
user avatar
0 votes
3 answers
171 views

Using the symbol ⎋ to denote any "escape" in Javascript, CSS, HTML etc

I know that: Computer keyboards have an Escape Key The symbol for the Escape Key is U+238B Broken Circle with Northwest Arrow (⎋) and I also know that: HTML5 & CSS3 both have escape characters ...
user avatar
-4 votes
3 answers
500 views

Should I prefix keys of JS object with the object's name?

Let's get to an example. Suppose, I have a Course object with the following properties: (course' code, course's title, credit of course etc.). When expressing this as a JS object, I can do it in the ...
user avatar
0 votes
1 answer
99 views

When does it make sense to update eslint/prettier?

I have the following setup: different teams shared eslint config (that imports airbnb rules as a basis). Whenever a developer decides to update libraries, if eslint/prettier have updates, it's a ...
user avatar
0 votes
2 answers
516 views

What approach do I take to unit testing a class which has a method that internally calls other methods?

I have a class which has one method that is called from another class. This method internally calls several other methods to do its work. Those other methods are all public and can be called by the ...
user avatar
-4 votes
1 answer
314 views

What is a good book to learn JavaScript for complete beginners?

I could not find a good book for learning JavaScript. I Googled but most books seem to assume that you have some programming experience and don’t teach from the ground up. They assume you should know ...
user avatar
-2 votes
1 answer
273 views

Design pattern for a switching between APIs with no code changes

I'm trying implement in JavaScript/Node.js a data upload functionality. I want to be able to switch between different storage providers, e.g. AWS, GCP, Azure, with no code change, for instance, via ...
user avatar
  • 135
2 votes
2 answers
443 views

React says refs and imperative code are not the right tool for showing and hiding dialogs. Why though?

The docs explicitly state this: Avoid using refs for anything that can be done declaratively. For example, instead of exposing open() and close() methods on a Dialog component, pass an isOpen prop to ...
user avatar
4 votes
3 answers
1k views

Testing unexpected inputs for unit tests and loops?

I'm working on an enterprise that has some Angular/Typescript projects and to avoid repeating code (basically copying and pasting) between them, we decided to go for Monorepo and start write an util ...
user avatar
  • 151
1 vote
2 answers
59 views

How to pass variable to function that may or may not be available based upon options?

I have a question and it is quite simple. Here are the details: I want to pass an options object into my mainFunction and some other functions inside of it, i.e. someFunctionCall and ...
user avatar
1 vote
1 answer
48 views

How could I optimize an AJAX-based site by avoiding unnecessary/duplicate file-reads for each AJAX call?

I'm an IT guy (read: not a professional programmer) and have made an internal monitoring webtool which allows users to search for printers on our print servers. Based on the filtering criteria given, ...
user avatar
  • 121
2 votes
1 answer
1k views

How to update HTML/JS client from PHP server without refresh intervals?

I am building a simple client-side web page that can be updated from an admin page. I am using PHP for server-side manipulation of the client targeted page. The setup feels like an overkill to me: ...
user avatar
  • 53
2 votes
0 answers
52 views

Javascript module design patterns

Partly for use in my own projects, and partly for fun while being stuck at home I'm attempt to build yet another "block" based editor. So far I've been using simple objects, starting with a global ...
user avatar
  • 227

1 2
3
4 5
42