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
1 vote
1 answer
113 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
513 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
77 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
211 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
232 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
39 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
174 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
112 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
185 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
256 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
122 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
101 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
192 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
302 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
512 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
101 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
175 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
232 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
9k 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
160 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
946 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
266 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
356 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
753 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
184 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
186 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
90 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
78 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
413 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
0 votes
1 answer
430 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
270 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
336 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
168 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
201 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
69 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
1k 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
282 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
0 votes
2 answers
2k views

Store static data in public folder as json file or directly in .js file?

I'm busy working on a website – somewhat new to this – and I don't quite know where I should store static data: in the public folder as a separate json file, or within the .js file as an object. In ...
AlePouroullis's user avatar
0 votes
1 answer
182 views

What can be done with closures that would be difficult or impossible to do without closures?

I am trying to understand what can be done with closures that would be difficult or impossible to do without closures. One use of closures I have found is to make an object's variables private, for ...
Christopher's user avatar
  • 2,039
-1 votes
1 answer
101 views

How to measure the impact of a website speed optimization

Given: You have a list of opportunities* that may improve the speed metrics of your website. For example Total Blocking Time (TBT) is one metric that heavily impacts the experience of a visitor. You'...
Jeremy Gottfried's user avatar
0 votes
2 answers
659 views

Should I use unnecessary function for readability sake

I am implementing if/else statement, by using function "inCase" to make it more readable: const size = 'small' const equals = str1 => str2 => str2 === str1 const inCase = (obj) => ...
Djordje Vuckovic's user avatar
0 votes
0 answers
561 views

Svelte & Vite Project - where/how to define constant values?

I have project where I use a url in various places. To prevent having to change it in all places, I would like to define it as a constant value in just one place which is referenced everywhere. But I'...
Corrl's user avatar
  • 101
2 votes
1 answer
164 views

Would invisible custom elements make sense?

The use case I was thinking about was something like this. I want to make a calendar for a month as a custom element, and I don't think passing up all the event data as JSON or something is the best ...
art-solopov's user avatar
0 votes
0 answers
85 views

Effective cache solution to have the newest data in React Native

Goal We have an app with different articles. I want to cache an article when the user has read it, but make sure that I display the latest data. I came up with this hook: React.useEffect(() => { ...
Gh05d's user avatar
  • 101
6 votes
2 answers
567 views

Is "this" in JavaScript out of fashion?

I'm not a frontend dev, but I recall that a few years ago, the this keyword was commonplace in frontend codebases. In recent years, I haven't seen this get used anymore. In the last few frontend ...
Newb's user avatar
  • 178
0 votes
1 answer
165 views

Verbs in Use Case name "Create User" [closed]

I'm struggling on how to name classes for use cases. Because I know that is "bad" to use verbs in classes names(Uncle Bob) but at the same time names of use case classes should explain what ...
Carlos Figueroa's user avatar
0 votes
0 answers
49 views

JavaScript: My logic traversing multi-dimensional arrays

Consider the following: Let's say below is the multi-dimensional, and you are given the starting point of [2, 2]. const WORLD = [ ['P', 'P', 'P', 'C', 'P'], ['P', 'M', 'P', 'C', 'P'], ...
Antonio Pavicevac-Ortiz's user avatar
1 vote
2 answers
1k views

How to authenticate front end with backend in an anonymous user flow [closed]

I have an API that will be exposed on the internet publicly, the primary use of this API will be initially by a ReactJs front end but in the future we'd be looking to open this up to other clients ...
A. Murray's user avatar
  • 171

1
2 3 4 5
43