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
0 votes
1 answer
61 views

Advice on data structure for an analysis and visualisation tool (javascript)

I am writing a browser-based tool to manipulate and visualise data (with D3.js). Currently, I store data in a JSON format, where each table is an object and columns are arrays. eg: { "data&...
user1505631's user avatar
0 votes
1 answer
87 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()...
KorbenDose's user avatar
0 votes
2 answers
162 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 ...
rpivovar's user avatar
  • 259
3 votes
3 answers
222 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(...
rpivovar's user avatar
  • 259
2 votes
1 answer
154 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 ...
RotundChinchilla's user avatar
5 votes
3 answers
528 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 ...
rpivovar's user avatar
  • 259
-4 votes
1 answer
92 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 ...
Qiulang 邱朗's user avatar
2 votes
1 answer
101 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 ...
Ennio's user avatar
  • 39
0 votes
1 answer
90 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,...
Blue Nebula's user avatar
0 votes
0 answers
39 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 ...
Tan's user avatar
  • 151
0 votes
1 answer
174 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 ...
Kricket's user avatar
  • 723
1 vote
1 answer
134 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 ...
azera's user avatar
  • 19
2 votes
3 answers
521 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 ...
agentroadkill's user avatar
0 votes
0 answers
138 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 ...
PHP Guru's user avatar
  • 101
1 vote
1 answer
368 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 ...
GeeWay's user avatar
  • 21
0 votes
2 answers
238 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 { ...
Tyler Del Rosario's user avatar
0 votes
0 answers
50 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 ...
Tania's user avatar
  • 1
0 votes
1 answer
322 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 ...
Dollique's user avatar
  • 101
0 votes
1 answer
207 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 ...
Jeremy Meadows's user avatar
3 votes
1 answer
210 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 ...
Meester Moo's user avatar
1 vote
2 answers
294 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 ...
Alex Ryan's user avatar
  • 127
0 votes
1 answer
134 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 ...
Anton Strogonoff's user avatar
1 vote
1 answer
130 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 ...
Cap Barracudas's user avatar
1 vote
2 answers
218 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 ...
tweekz's user avatar
  • 227
0 votes
2 answers
341 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. ...
devleo's user avatar
  • 51
1 vote
2 answers
2k 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 ...
Brk's user avatar
  • 31
1 vote
2 answers
103 views

JavaScript: Change prototype chain to morph objects from a deserialized JSON to business objects

This post assumes, that dtos on the UI side (SPA) could be viewed as business objects in almost all cases - except that the business logic is missing. I'm fully aware that a dtos first responsibility ...
morpheus05's user avatar
0 votes
2 answers
315 views

synchronize HTML5 or JavaScript video to realtime?

I will have multiple cellphones playing videos in an art gallery. The video content must be synced to the lights, which are synced to the real-world clock. As in, at 1:00pm the lights go out, 1:15 ...
prismspecs's user avatar
0 votes
2 answers
288 views

ECMAScript Primitives: Immutability vs Value Type

Coming from languages like C++, Java or PHP I've learned that there are Value Types and Reference Types. Value Types store values directly in the variable (in a box / memory location). Whereas ...
tweekz's user avatar
  • 227
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; ...
Lenny Zhou's user avatar
0 votes
2 answers
178 views

ECMAScript specification of primitives and objects

When reading through the ECMAScript specification, I noticed, it actually never mentions concepts like "pass by value" or "pass by reference". When looking at the assignment ...
tweekz's user avatar
  • 227
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. ...
BurstWizard's user avatar
-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 ...
bluedevil2k's user avatar
3 votes
1 answer
282 views

Do the maintainers of JavaScript remove features?

Really dumb question. I really like the new feature called "optional chaining" in JavaScript, and it's used in quite a few places in my front end code. However, I am concerned that whoever ...
Rongeegee's user avatar
  • 167
0 votes
2 answers
410 views

Extensive use of global variables in js codebase?

I've been tasked with refactoring/simplifying the architecture of a (relatively) large node.js codebase and it makes ample use of global variables. I don't have much experience with javascript so just ...
amy's user avatar
  • 111
1 vote
1 answer
1k views

What are the benefits of keeping npm packages up-to-date? [closed]

The company I work for is maintaining and developing a web application that uses many Node.js packages. A lot of these packages are really outdated. I can intuitively understand that it is good to ...
Akaisteph7's user avatar
1 vote
3 answers
187 views

How can I mix this grid to guarantee it being solvable in X minimum steps?

Note: This question is not about this particular instance of this grid with these exact words, but about any combination of words. I am programming a puzzle game where you have to arrange a grid of ...
Florian Walther's user avatar
1 vote
1 answer
261 views

Can I separate methods into different classes by passing in constructor properties from one class to another?

I am making a game of monopoly. Inside my game I have a Board class. The Board class has an array which contains 40 squares. Each square is a different class e.g. ChanceSquare, PropertySquare ...
Kevin Greetham's user avatar
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 (...
Joshua Frank's user avatar
1 vote
2 answers
80 views

Crossbrowser testing FrontEnd apps in 2022

So nowadays, creating js & css that works the same across different browsers is less of an issue as to what it was a few years back. So let's say I have this Vue app that - Has CSS reset Include @...
Haim's user avatar
  • 119
5 votes
4 answers
480 views

Does my outer class adhere to the Single Responsibility Principle?

I often write front end apps with a generic MVC pattern. I use javascript but this questions is language independent and relates to OOP as a whole. I struggle to understand the SRP principle and I ...
Kevin Greetham's user avatar
1 vote
1 answer
519 views

Is this a good example of what a service layer is in MVC?

I am wondering what a service layer is in MVC. I like to understand concepts through a game of monopoly as it's relatable to a lot of people and fairly easy to explain whilst allowing for some good ...
Kevin Greetham's user avatar
0 votes
2 answers
299 views

How can I achieve polymorphism if MVC logic is on the controller?

First, let me start by saying I’m a JavaScript developer but any conceptual advice I’d imagine is identical if not similar to when dealing with MVC. During my learning, I stumbled across MVC and now ...
Kevin Greetham's user avatar
4 votes
2 answers
416 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 ...
Nikster2014's user avatar
0 votes
1 answer
170 views

Is it premature optimisation to test a condition to skip a small loop?

I have an array of entities which have an id property: entities: {id: string|null}[] = []; All items in the array are guaranteed to have id !== null and the array will not exceed 100 items. Now I may ...
lampshade's user avatar
  • 103
2 votes
3 answers
202 views

Eliminating combinations based on user input

I am stuck with this particular problem. To give context to the problem, I am developing a mobile app which helps with loading dangerous goods onto a truck. Ignore the size and weight of the dangerous ...
Saul Goodman's user avatar
-3 votes
1 answer
72 views

HTML Playground [closed]

I'm creating a service for creating web tools. The tool is a generated web page with some JS engine. The user can interact with the JS engine through the user interface. The user interface can be ...
christo's user avatar
  • 105
1 vote
1 answer
2k views

Difference between Resolvers and Controllers?

I may be overthinking it, but are controllers and resolvers the same thing in web applications? Coming from the MERN stack, everyone used to call these request processing functions "controllers,&...
twominds's user avatar
  • 129
1 vote
3 answers
234 views

Does it always take the same amount of time to retrieve the same thing from collection?

for example: const arr = [1,2,3,4]; const coordinate = [arr[0] + 2, arr[0] + 1]; here arr[0] is written out twice, when the code is executed would it literally go and find same value twice or would ...
link2name's user avatar
1 vote
2 answers
296 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 ...
Jesper's user avatar
  • 143

1
2 3 4 5
43