Skip to main content

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
2 votes
1 answer
132 views

How do I properly organize JavaScript files for web development?

I am fairly new to web development and have been trying to figure out the best way to organize my JavaScript files for the front-end. The first approach I started with was "one JavaScript file ...
0 votes
2 answers
149 views

How to filter "locally and remotely" in functional programming

My example applies to reading and deleting files (I/O), but this is probably a common scenario (eg, keeping local and global state in sync in functional programming). I am reading in files from a ...
0 votes
1 answer
75 views

MongoDB schema: optional vs. nullable

If I have a schema that includes fields that may or may not be set, what is the best way to handle these fields? Should they be optional or instead nullable? Here an example (Mongoose/NestJs) @Schema()...
3 votes
3 answers
181 views

How to "pass through" data in a functional programming pipeline so that it's accessible later on in the pipeline

I am trying to refactor some JavaScript code to use functional programming principles. I have some functions that I want to use in a series of maps. const transformedData = rawData .map(...
5 votes
3 answers
481 views

Are "pipelines" in functional programming bad for time complexity?

This question is not meant to be a critique of functional programming, but more hoping for resources and opinions. I am refactoring some historically messy code so that it follows functional ...
1 vote
3 answers
1k views

Best strategy to push client-side updates to server?

I'm just starting to build a web app using React.js, Next.js, Prisma, & PostgreSQL. In this web app, users can create "projects", which are represented by 10-15 rows in the database. ...
-4 votes
1 answer
84 views

Refactoring the testing code inside a big switch code block

The main logic of my function is a switch case, with the default case being the abnormal case. function main(input) { let result = process(input) switch (result): { //normal cases case ...
84 votes
6 answers
24k views

Why do many software developers violate the open/closed principle?

Why do many software developers violate the open/closed principle by modifying many things like renaming functions which will break the application after upgrading? This question jumps to my head ...
2 votes
1 answer
98 views

Concrete implementation of MVP with "dumb" view

I recently started designing my first MVP-app. I like the idea of having a "dumb" view to be able to cover as much of the code with unit tests. The app I build will be an app to create ...
0 votes
1 answer
82 views

Is it bad practice to export all the names from one module both as named exports and as a default export?

I like to export the names in my modules both as individual named exports and grouped together in a default export. Like this: // mod.js export function f() {} export const x = true export default {f,...
1 vote
1 answer
1k views

Angular2: Service architecture + error handling

I need support for Angular2 service architectures. I am quite familiar with Angular2 but I don't see the best way to implement services, error handling and their connection with the components. I'm ...
0 votes
0 answers
37 views

Need advice on approaches to saving data

The following code(JSFiddle here) is a grid-based code where I'm performing the following steps: I’m moving blue boxes from left to right (on the grid) after clicking Move Text Content! button. Here ...
1 vote
1 answer
477 views

Organizing reducers in Redux

I will use the following popular todo list example for demonstration. Let's say I wanted to create a very basic todo list with this structure as the app state: { todos: { todoKey1: { ...
0 votes
1 answer
153 views

Best practice - depending on object key iteration order?

In Javascript, the iteration order of an Object is enforced since ES2020 (or before, depending...). However, is it a good idea (i.e. best practice) to depend on this? I'm currently working on a ...
2 votes
2 answers
568 views

How to get an object that another object is prototype of?

Javascript in the DOM has a peculiar characteristic. There's a different Object object that an object (by default) inherits per window. In order to find what kind of object is being sent to a function ...
4 votes
4 answers
2k views

Best practice in synchronized form data validations (Web apps - Client-Server)

Here we go again with topic what was asked many times all over internet, but I not found any good enough answer: What are best practices in making client and server side validations synced? I was ...
0 votes
2 answers
330 views

Local development for TypeScript library organized as mono repo with Lerna

I currently am developing a TypeScript shared library. The library needs to be imported in sections to minimize the imported bundle size, so I broke it up into packages with a monorepo with Lerna. ...
1 vote
1 answer
292 views

Potential Solutions to loading Javascript classes unknown at run time

I'm looking for some advice or potential options for loading javascript files in real time long after the DOM has fully loaded. Those javascript files need to be sent over a WebSocket connection, and ...
1 vote
1 answer
130 views

Refactoring to nested functions inside methods (JavaScript)

I've been reading Refactoring (2nd) by Martin Fowler. In the first chapter, he shows an example of refactoring a function where he extracts other functions from it and places them inside that function ...
2 votes
3 answers
518 views

Critical Infrastructure Language Selection

I took over a development team working on life-safety critical software earlier in the year. The product has been in development for about 8 years, but the current team has only been working on the ...
44 votes
8 answers
12k views

Why not embed styles/scripts in HTML instead of linking?

We concatenate CSS and JavaScript files to reduce the number of HTTP requests, which improves performance. The result is HTML like this: <link rel="stylesheet" href="all-my-css-0fn392nf.min.css"&...
1 vote
1 answer
91 views

How to develop data bound html with strong typing and intellisense?

I'm a huge believer in the value of Intellisense for showing you what syntax is expected and allowed (and also saving typing, though this is a secondary consideration). When you build a web component (...
4 votes
1 answer
954 views

DDD / Onion architecture in JavaScript

One reason I like .NET is because the 'solutions' and 'projects' lends themselves to good architecture. Good architecture makes it easy to follow the happy path of Domain-Driven Design. I've fallen ...
6 votes
6 answers
830 views

are magic strings as event names okay

I am about to create my own event-driven API in JavaScript. Most JavaScript that currently exists, e.g. in-browser JS for controlling the DOM, lets you register event handlers like this: object.on('...
0 votes
1 answer
293 views

Array structure for nested grouping (JavaScript)

I am currently struggling with how to solve nested grouping of data. The initial structure is given and my grouped structure below as well as my approach can be adjusted. My idea was to have the array ...
84 votes
2 answers
75k views

Is localStorage under The Cookie Law? [closed]

I'd like to avoid having the cookies banner on my websites where possible. Could I store session id's in localStorage to bypass implementing the banner?
0 votes
0 answers
127 views

What is a forged redirect? (in the context of javascript's fetch API)

I'm trying to make sense of the docs located at: https://developer.mozilla.org/en-US/docs/Web/API/Response/redirected It says Note: Relying on redirected to filter out redirects makes it easy for a ...
1 vote
1 answer
342 views

Using JS and CSS parent selector to replace media queries: is it a good practice?

I really don't like media queries in CSS - they have limitations, and on top of that they make the code a lot more confusing. In addition, the restrictions are so strong that when using CSS ...
4 votes
4 answers
13k views

flow control solutions in Node.js - use async.waterfall?

Looking at node.js, and avoiding nesting callbacks. I found Async.js, can someone show me how can I rewrite this code using the async.waterfall method? // db is a mongodb instance db.open(function(...
0 votes
2 answers
237 views

Is circular referencing required in this situation?

class ItemList { constructor() { this.list = [];//list holds many instances of Item Class } removeItem(id) { //...search for item in this.list, remove it } } class Item { ...
1 vote
2 answers
293 views

Is it a bad habit to use other class' "private" variables in Javascript

I've gotten this idea in my head that i shouldn't use a libraries variable, if the variable name begins with '_', as it is standard to write private variables that way. But now i'm thinking i'm taking ...
4 votes
2 answers
391 views

What would be the reason for using asynchronous programming on a web server?

I have a python/php background and just about to start work on a NodeJS project which is why I have this question. I have worked a bit on frontend JS but this is the first time I will be using JS for ...
-1 votes
1 answer
99 views

"Select All" in Table is now sending too much data to Server via API - Alternative Ways to Send to Server?

Outline of the current architecture of our web app outlining the issue I'm seeing Client-side app is React, talking to a server running the Play! framework via an API. On the page is a table that ...
13 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 ...
0 votes
0 answers
46 views

Storing SVG settings in a global variable to retain its contents during resize - acceptable?

In the solution I've been asked to maintain (Meteor based app), there are several responsive SVG charts. When the page is loaded, settings for each chart are stored using the following: <input ...
2 votes
1 answer
2k views

How do you handle time unit constants (second, minute, etc)?

I've been writing a lot of time related code recently, and in various files, I always end up re-defining things like var SECOND = 1000; var MINUTE = 60 * SECOND; This gets frustrating quickly. So I'...
0 votes
1 answer
182 views

HTTP redirect vs JS redirect

I have a Svelte web app exclusively for internal use, so there is no main landing page or registration, as accounts need to be created by the admin. Since the main page has no function as an ...
3 votes
1 answer
205 views

Is it good practice to always use "use strict" in modern web apps? [closed]

I'm learning JavaScript and just came across "use strict". It sounds like to me it should always be in play but me being a beginner I was wondering if there are scenarios/environments when ...
1 vote
1 answer
121 views

Is module scoped initialisation considered a bad practice?

A module app.js includes another module service.js. The service.js module/file contains some functions but also does some module scoped initialisations(registry variable). // service.js const ...
7 votes
6 answers
24k views

Securing ajax calls to rest api

I need for my app to consume a rest api service and since I will call it from javascript/jquery i need to expose it to the end user. In this case I would also need to expose credentials to the end ...
1 vote
2 answers
287 views

Why did TC39 name JavaScript's array predicate functions `some` and `every` instead of `any` and `all`?

Python, Ruby, Rust, Haskell, Kotlin, C#, C++, Perl, MATLAB, SQL, and R all call their respective array predicate checking functions any and all. Is there any record of why JavaScript's designers ...
0 votes
1 answer
131 views

Why is `WeakSet` great for tracking circular references?

In MDN article on WeakSets, an example is given for using weak sets to avoid infinite recursion on circular references: // Execute a callback on everything stored inside an object function ...
3 votes
1 answer
422 views

Dynamic execution of Template Literals using a Map

I have a system that is generating internal events for objects. I am extending their debugger to display a human-readable version of the events sent to the debugger. For instance, the system will ...
0 votes
1 answer
465 views

How to avoid code duplication caused by javascript dict access?

I have two functions that group a list of dicts according to the value of a certain key. Here's how my array looks: const sections = [ { file_id: '1', heading_level: 4, readme_file_name:...
-1 votes
2 answers
937 views

any website monitoring library/modules to use in my website? [closed]

I'm trying to build a site which user can add their websites which should be monitored and can view a detailed report and statistics of it. And also it should be able to monitor local webservices (...
1 vote
2 answers
214 views

Variable assignment in ECMAScript specification in detail

I am trying to wrap my head around what the ECMAScript specification suggests about variable assignment. Introduction: Coming from Java, this is pretty straight forward. Variables get stored at a ...
-4 votes
1 answer
124 views

Creating a multiplatform (IOS, Javascript, and JAVA) linked user account database

I have done weeks researching this question for my App Idea. Background of the APP - Simply a multi crypto currency wallet which users sign up with ONLY username and Password - no email, FB, or ...
1 vote
2 answers
1k views

How to represent the absent of a field value in json response?

I am a react developer and writing the client on pure JS. I have sometimes missions to received data from server and send data to server. Now between the client team and backend rough discussion ...
10 votes
3 answers
2k views

What is the point of the prototype method?

I am reading through Javascript: The Good Parts, and struggled to get my head around the section on prototypes. After a little google, I came to the conclusion that it is to add properties to objects ...
26 votes
8 answers
10k views

Is it okay to hard-code table and column names in queries?

I've got a backend running on Node that executes queries on a PostgreSQL database. For these queries, table and column names are imported from a .env file, for example: const ID = process.env.ID_COL; ...

1
2 3 4 5
43