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
15 views

Is it a bad idea to persist a javascript function?

I'm working on eventual consistency. In short I have a bunch of promises and I want to make sure they get retried until they succeed. It would make my life a lot easier if I could just persist the ...
-1
votes
1answer
12 views

How compiler and interpreter both are used in one language?

After writing the complete code the compiler compile the whole code at a time , but on the other hand interpreter take single line at a time. Both the compiler and interpreter are mostly called the ...
1
vote
2answers
89 views

How to write unit tests a method with a result that is highly based on another method [duplicate]

How to write unit tests a method with a result that is highly based on another method ? async function getStatus( session, correlationId, data ) { const client = new SomeAPIWrapperClient({ ...
2
votes
1answer
22 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
58 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 {...
1
vote
1answer
155 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
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 ...
0
votes
0answers
27 views

How to isolate seperate organizations data using databases [closed]

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
73 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
57 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 [closed]

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
86 views

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

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. ...
2
votes
0answers
23 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
2answers
294 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 ...
1
vote
7answers
670 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
0answers
36 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 ...
1
vote
4answers
91 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 ...
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 ...
-1
votes
1answer
48 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 ...
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 ...
0
votes
1answer
170 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;...
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
121 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
25 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
32 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
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 ...
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) { ...
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
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 ...
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() { ...
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 ...
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 ...
0
votes
1answer
46 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 ...
0
votes
1answer
83 views

What does await do in JavaScript?

Sorry for this naive question. Reading some existing JavaScript I see a function with code like ... async function _load() { await ensureDir(path); return await readFile(filename); } ... why ...
-3
votes
1answer
42 views

How does event.target return the DOM object?

I read through documentation and searched on google, but couldn't find a specific answer. Currently, I have an object that subscribes to a click event. I am trying to understand how a view that ...
7
votes
2answers
442 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; ...
0
votes
2answers
68 views

Should / When to create javascript object to serialize data?

I'm working on a React/Redux application. I receive a data object from the api resembling this: const dataObj = [ { id: 1, name: "Filo", activity: 9, info: { statusCode: 4 ...
0
votes
1answer
54 views

Load files depending on browser or write workarounds within the file?

I'm writing up this website running under IIS with .NET Core. I developed most of the site with minimal use of JS so that the server will be doing most of the work (and thankfully so because of the ...
-1
votes
1answer
81 views

Would I need a web framework if the app is running locally and not in the net?

I need to make an Employee Payroll application and the client specifically stated that the application will run on their computer locally and will not be hosted anywhere in the internet. I can code ...
1
vote
2answers
144 views

When using Redux/Redux-Saga - should JWTs be set in the action creators/sagas?

Almost every blog post I've encountered around generic auth handling using JWTs in a React/Redux/Saga application does the same thing, which is to store the JWT in local storage, in the action/saga. ...
1
vote
3answers
250 views

What algorithm is used in subtitles?

What algorithm does a video player use to find the subtitles to show at any given time? I'm building a video player that displays some notes on different times over a video. Each note has a starting ...
0
votes
1answer
136 views

Why are React keys limited to strings?

In React, when rendering a mapping from elements of a list/array/iterable to React elements, we're required to attach a locally-unique key to each element. Generally this is so that if an element ...
2
votes
1answer
41 views

continuous deployment of web application built with multiple packages

Our react web application is broken down to multiple components. Some of these components are part of the same git mono repo and some live in a different repo. Now, to implement a bug fix we have to ...