Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

0
votes
1answer
8 views

How do you remove property a from this object? [on hold]

I am facing problem in JavaScript. How do you remove property a from this object? let a = (a:1,b:2) .
0
votes
1answer
10 views

handle file downloads from the server

I am wondering if the following would be a good technique to allow user to download files from the server in the below scenario: Info about the scenario: User logs into a system (HTML,JQuery and CSS,...
1
vote
1answer
139 views

Which programming pattern is best for checking which partition a number lies in?

I have an interval partitioned into “MECE” subintervals, and I want to check which subinterval a number lies in. (MECE stands for “mutually exclusive & collectively exhaustive”, meaning the ...
1
vote
1answer
57 views

ES6 - Where is it better to initialize a member - parent class or derived class?

I am trying to figure out if there is a better practice for initializing class members of derived classes in ES6 - in the child or the parent, and why? For example: Option 1: class AbstractAnimal {...
32
votes
3answers
18k views

Any point in using ES6 Map when keys are all strings?

Plain object keys must be strings, whereas a Map can have keys of any type. But I have little use for this in practice. In nearly all cases, I find myself using strings as keys anyway. And presumably ...
1
vote
1answer
106 views

Should a function implementer or function caller handle immutability

I know there is no right and wrong answer here, I'm just looking for other opinions on who should handle immutability, dependency inversion and decoupling. Example 1: Here each function caller has ...
6
votes
2answers
2k views

React: Nested object as state vs individual properties

Are there any use-cases where a nested object as state is either more optimal/easier to work with than individual properties? For instance if I wanted to express some user controls for interacting ...
0
votes
0answers
27 views

How to isolate seperate organizations data using databases [on hold]

A new project I am about to begin will require isolated data for each organization that registers. Ideally, each would be accessible with unique credentials. I want to use either Firebase or AWS for ...
0
votes
2answers
72 views

Website Multi Languuage [closed]

I have one website and the website are now in HTML, that actually is structured: domain.com = English domain.com/es = Spanish domain.com/de = Germany I copied the HTML of English page to Spanish ...
1
vote
1answer
55 views

How function parameters are compiled in JavaScript

I am trying to understand how functions -- which could have dozens of parameters that could themselves be functions or complex objects (I'm thinking JavaScript) -- get passed the arguments when ...
0
votes
0answers
46 views

Prevent scrolling in a child element from scrolling the ancestor [on hold]

I have a nested element that is scrollable just because it has more content than its designated height, thus I don't actually handle the scroll events. my problem is that when there is nothing more ...
-3
votes
0answers
83 views

Technically, is it possible to code JavaScript in frontend to manipulate a database like MongoDB? [on hold]

I know it is the job of the backend to manipulate a database; for JavaScript, we could use Node.js to talk to a database like MongoDB. However, I want to write some scripts to use locally by myself. ...
1
vote
0answers
17 views

Dynamic API Data Validation

I am in the process of building an heavily data-driven web application written in Node.js / Typescript with Mariadb for the database engine. I am trying to put an emphasis on extensibility and DRY ...
1
vote
7answers
647 views

Why don't languages not use the words “and” and “or” instead of “&&” and “||”?

When I was a beginner it took a while to learn the language syntax and the idea that languages couldn't improve after they were invented. But now we're seeing new language features added every year ...
1
vote
4answers
89 views

filter + map api design

I am writing a library call that will allow you to filter and map in the same iteration of the loop, this is async/callback style in Java. The problem of course is that for filtering we usually return ...
1
vote
2answers
289 views

Avoid if-else block in favor of default assignment followed by if

A colleague, and frankly better software engineer that me, is telling me that this pattern let variable = someDefaultVariable(); if (some_boolean) { variable = someOtherValue(); } is better than ...
4
votes
1answer
2k views

Microservices Architecture separating backend and front end

We are trying to move (slowly) into Microservices architecture from our current monolithic based architecture. I've done my research on microservices architecture and would like to get some feedback ...
-1
votes
1answer
46 views

RPC with Express JS? [closed]

I've been working on a project recently where I have an Expressjs server that supplies weather forecast data to its clients. Right now, I'm using express simply as a means of exposing some functions I ...
1
vote
0answers
35 views

Best practices for positioning elements in an HTML-based game

It seems like HTML5 has about a zillion different layouts and methods for positioning divs, few of which seem to work exactly as described in most browsers. Imagine an implementation of, say, Tetris ...
0
votes
1answer
58 views

Push partial result to user [closed]

I'd like to build a small system which takes a user input in a web page, submits the information to a backend, which subsequently calls a few different apis, and then updates the user with the results ...
0
votes
1answer
169 views

Writing C# utility that checks on property

I have a business requirement that requires checking on a person's first name to ensure it does not have the character "1". The model: public class Person { public string FirstName { get; set;...
0
votes
1answer
87 views

Structuring methods in classes [closed]

When implementing a class (in any language), I usually try to pack any associated code in small methods, may they be used only once or multiple times. Finally, I end up with a class consisting of a ...
1
vote
1answer
37 views

Efficient and readable method for styling of javascript webcomponents

I have a web page that loads a very long list of custom web components, each with their own shadow DOM and a stylesheet shared by all instances. Originally, I included the stylesheet as css file ...
-1
votes
1answer
120 views

Does avoiding Promises and Async leads to clean code?

While applying for a job interview I found this line in requirements. Experience with clean code writing practices like avoiding callback hell like promises, async Does this line make any sense ? ...
0
votes
0answers
22 views

Messaging engine architecture with front-end and ORM layer (spring)

I'm looking to push my first QuickFixJ messaging engine into production, and I would like to know the best way to do so. Bear with me. The gist of the responsibilities is as follows: Through ...
1
vote
2answers
153 views

Is it bad practice to leave hidden elements in the dom?

I'm looking for perspectives from other web/ui developers. I'm a UI developer and my company requires that I use components built by another team within the company. That team has developed some ...
0
votes
3answers
142 views

If callback function, promises and async/await patterns all can be used to achieve asynchronous behaviour then why don't we stick to one?

As far as I have seen then async/await, callbacks and promises are and can only be used to achieve asynchronous programming. Correct? So my questions are: 1) Is it correct that the former three is ...
2
votes
0answers
84 views

What is the state of immutability in Javascript in 2019?

I'm all on board with functional programming in Javascript - particularly within the context of using React and Redux. Something that I've been running into again and again, is how easy it is to ...
0
votes
0answers
31 views

Extending prototype

I am currently refactoring a project where I come across the following kind of code multiple times: propertyFunction: function (feature) { doSomethingOnyWithFeature(feature); ... } Methods, that ...
0
votes
1answer
95 views

Difference between a strongly typed language and a weakly typed language with type annotations from the developer's point of view?

I understand that there are major technical differences between how a strongly typed language is compiled and how a type annotated language is compiled/transpiled. But as a developer writing in a ...
0
votes
1answer
88 views

What is the original reason JSON used `null` and not `undefined` to represent missing values?

In Javascript, there seems to be or have been an idea that undefined represents a missing primitive OR object value, while null represents just a missing object value. See, for example, this section ...
0
votes
1answer
56 views

Adding custom properties to Javascript Objects of external libraries - is that considered bad practice?

I regularily come across code that stores some custom properties in JS Objects from external libraries, for example: /**@param OpenLayers.Feature feature */ function doSomething(feature) { ...
0
votes
0answers
51 views

Two Web clients and Java server (HTTP and Websockets)

I have 3 software components of a Web Application: 1. JS-client application 1 (JSApp1) 2. Java Spring (REST and Websockets) server app (SRV) 3. JS-client application 2 (JSApp2) My current task is to ...
1
vote
1answer
307 views

How do functional programming advocates use a framework like React or Angular?

I read this blog post recently: The Two Pillars of JavaScript Part 1: How to Escape the 7th Circle of Hell, which is essentially a criticism of object oriented programming, and advocacy for funtional ...
1
vote
1answer
19 views

Geolocation client side requests: Key and ID storage

I'm developing a small web-app to help users manage shopping lists. One of the required features is the ability of the application to notify the user if a shop of the same category is near him/her. ...
1
vote
4answers
262 views

In Haskell, is it a “violation” of functional programming to interact with something that was not a function parameter?

I'm sure this must have been asked before, but I can't find anywhere that actually answers my question, so apologies if I have simply overlooked this. I am currently learning Haskell, and loving the ...
1
vote
0answers
78 views

Refactor MVC to more scalable architecture?

Months ago I began a new web project which, in the beggining, seemed like a small application with virtually few users. I began the project by using the awesome Hackathon Starter WebApp Boilerplate by ...
1
vote
1answer
33 views

Should I run my tests against production build transforms (i.e. Babel)?

A coworker of mine recently setup testing in a new project (a JS library) where a transform step hooks in to the babel config for Webpack in the production config. For reference, this is the setting ...
1
vote
1answer
144 views

Why (historically) do `+[] === 0` and `+{} === NaN` in Javascript?

In Javascript, converting [] to a number (e.g. +[]) gives 0, while doing the same to {} gives NaN. This leads to entertaining wats like this: > 2 / [] Infinity > 2 / {} NaN Is there a ...
1
vote
1answer
2k views

element.style.setProperty(property, value) vs element.style.property = value [closed]

I was wondering if I should use element.style.setProperty(property, value) or element.style.property = value. I am very much tempted to start using element.style.setProperty(property, value). But in ...
6
votes
1answer
3k views

Why doesn't v8 compile typescript instead of javascript? [closed]

Since Typescript is just a superset of javascript (every javascript program is also a typescript program), I've got this idea - why doesn't v8 support typescript? or anything statically typed ...
0
votes
0answers
22 views

How can I manage the state of my application using a dedicated object instead of what React offers?

Most of the react application I've seen are organized with components that, in my opinion, do too much. They may follow this pattern: class MyComponent extends Component { constructor() { ...
15
votes
5answers
7k views

Algorithm for flattening overlapping ranges

I am looking for a nice way of flattening (splitting) a list of potentially-overlapping numeric ranges. The problem is very similar to that of this question: Fastest way to split overlapping date ...
10
votes
5answers
1k views

Is it beneficial to study past the basics of a core language when the primary goal is to rely on its framework? [closed]

Please keep in mind this is not another 'How much [insert programming language here] should I know before moving onto [insert framework here]?' What I'd like to know is how beneficial is it to learn ...
0
votes
1answer
57 views

Uploading file to the server for download

I've my front end written using HTML/CSS/Javascript. Front end is communicating with the backend(Oracle database) using Java Webservices (Spring boot app). Situation #1: User clicks on the Download ...
10
votes
3answers
490 views

What does it mean to inject data (vs behaviour) in a class constructor, and why is that considered bad practice?

I am reading the book "Learning TypeScript" by Remo Jansen. In one section the author describes how to create a very simple proof-of-concept MVC framework including how to create the Model class and ...
7
votes
2answers
423 views

A real-life example of using curry function? [closed]

I was struggled to find a real-life example of using curry function and get the benefit of using curry. When I google curry function I often see the example like let add = x => y => x + y; ...
1
vote
1answer
92 views

Methods to Securing APIKeys

I have read on several methods to securing an API key like gitignore or placing in another file if using an application, but at some point if taken the time, anyone can get the key, even when apikey ...
3
votes
1answer
712 views

What is a good method of storing test data for development and unit testing with angularjs and jasmine?

What is a good method of storing JSON data/objects for development and unit testing with angular and jasmine? I have seen some ways of accomplishing this. However, since I am new to unit testing with ...
0
votes
1answer
45 views

Split large Angular codebase to libraries

I am writing a potentially large web application using Angular 7, where I came across a design problem. My angular applications until now have been relatively small, so there was no problem keeping ...