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
3
votes
1answer
180 views

How to name two functions that could be named the same?

I have a node app with a queue for processing jobs in the background. I have a file that exports a function which when run, creates a job in my queue. In that file, I also have the handler for this ...
-4
votes
2answers
3k views

Reliable device/browser/OS detection [closed]

Is there some reliable way to detect device/browser/OS of web page visitors except using the user agent string? This is not for rendering/functionality of the web page/application, but only for ...
0
votes
1answer
102 views

How to statically check you didn't forget to await for an async function

A common bug in JavaScript is to forget the await keyword when calling an async function. Of course you don't always want to await, sometimes you really want to get a promise. And of course you can't ...
31
votes
8answers
15k views

Does comparing equality of float numbers mislead junior developers even if no rounding error occurs in my case?

For example, I want to show a list of buttons from 0,0.5,... 5, which jumps for each 0.5. I use a for loop to do that, and have different color at button STANDARD_LINE: var MAX=5.0; var DIFF=0.5 var ...
-3
votes
1answer
94 views

Is there a best practice for naming class selectors for identification alone

Is there a best practice for naming class selectors for identification alone? For example, for defining a single amount field with action button, we end up creating several div containers and div ...
0
votes
1answer
47 views

Performant way for archiving image files in NodeJS on each user requests

Scenario: Images are uploaded to the server once in a while. Users send an API request for downloading all of those images that were uploaded to the server (Images reside in the server itself). ...
1
vote
1answer
251 views

Why bother with server-side form submissions in a SPA?

I am all in favour of progressive enhancement and using server-side rendering when fetching a URL. The age-old discussion gives several advantages, such as improved load time, SEO crawling and ...
0
votes
0answers
407 views

What is the cleanest way to model my domain in JavaScript?

I am building an SPA. It will use WebGL, Canvas and SVG for certain components, and html for rendering views. I have a messaging system setup to define messages coming from a server, which will get ...
2
votes
4answers
419 views

JavaScript only validation on AJAX form submit

I've been mulling this question over for a few days in my head and I can't come to a solid answer. We understand that client side validation for forms is not enough, because you can easily turn ...
3
votes
3answers
766 views

REST Api - Check if Action is allowed for entity

I'm asking this question for a colleague since he doesn't have enough reputation to post images in a question During our normal development we found a deficit in our REST Api. We display entities in ...
9
votes
2answers
2k views

Why use `const foo = () => {}` instead of `function foo() {}`

For example, in this Redux video, the instructor always uses syntax like const counter = (state=0, action) => { ... function body here } where I would just use the "traditional" function ...
4
votes
1answer
1k views

Python and JavaScript integration for offline use

I'm a first timer here so let me know if I should post this question in a different forum! I have a python program that takes in user input but is only useful when you're offline, I wanted to make ...
10
votes
1answer
502 views

Why most anonymous functions can't be JIT compiled and will never be optimized?

I just read https://techfindings.one/archives/2652 about functional programming and came accross this: anonymous functions can often not be JIT compiled and will never be optimized Can someone ...
2
votes
2answers
487 views

Polymorphism based on number of arguments?

I've heard that changing a function's behaviour based on argument type is called ad hoc polymorphism: program Adhoc; function Add(x, y : Integer) : Integer; begin Add := x + y end; function Add(...
0
votes
1answer
211 views

When to use stubs

I'm trying to get into TDD, and a lot of examples sugests that we should use stubs to make our code more flexible. If I'm using javascript (for example) then why should I use stubs, since methods and ...
2
votes
0answers
128 views

Is there an accepted Coding Style for multiple ES6 Arrow Functions?

I'm starting to use ES6 arrow functions more, but haven't found a coding style that I like, especially when chaining them together. e.g., Eric Elliott gives this code: mix = (...fns) => x => ...
-4
votes
1answer
6k views

Using forEach on empty array [duplicate]

I have a dynamic array that can often be empty, and I need to iterate over all its elements. So far I have such code: array.forEach(function(item, index) { //stuff here }); It works fine of ...
0
votes
1answer
130 views

How to plan unit-test design/structure for Javascript?

In opening I would like to say; I'm pretty new for programing. I'm working with JS for a year. Using Sencha's ExtJS and usign Bryntum's Siesta test tool for unit and integration(ui) tests. Right now ...
1
vote
0answers
44 views

Exporting functions usable by both client-side and server-side

So this isn't a question on how to do it, but more of a clarification on how it works. I'm using Vue and I'm creating a file that's usable by on both the client side and the server side (logic should ...
-1
votes
1answer
298 views

How to extract SSML parsing code of espeak to implement SSML parsing at SpeechSynthesisUtterance?

eSpeak implements SSML parsing. SpeechSynthesisUtterance, at least as implemented at *nix, does not parse SSML input at Chromium or Firefox browsers. How to identify and extract the relevant portions ...
0
votes
1answer
67 views

What types of operations should go into Node.js as opposed to client side javascript functions

I am building a web app with a lot of different API calls: our own proprietary REST API, third-party library API calls, etc. All of these calls either retrieve data, update data, delete data, or ...
1
vote
3answers
988 views

How to handle parallel requests, different response time and atomicity of transactions

I have a table of data and I can create , update and delete rows. I have apis to do these operations. The following steps happen I create a row and send a create request to server. I update some ...
1
vote
1answer
94 views

What is the best way to store message threads?

I'm integrating a messaging feature into an application written in Javascript and would like to know which is the preferred data structure of storing messages. The two structures I can think of so ...
1
vote
1answer
460 views

Angular template variable reference [closed]

Here is a weird problem in Angular: <input #pin1 type="password"> <p>You entered: {{pin1.value}}</p> If you type something in <input>, the <p>'s content will not change ...
3
votes
2answers
874 views

How to write good javascript unit test descriptions

I come from a python background. I typically write long unit test descriptions that link the test to a user story. The test is as much about justifying why the code exists and how it fits into the ...
0
votes
1answer
718 views

Difference between JavaScript self-executing function and constructor function in private methods

I know this has been asked many times before, but I still don't quite understand what the difference is between the following: var Foo = function (){ //1 this.a = ""; this.b = ""; var ...
6
votes
2answers
3k 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 ...
4
votes
1answer
833 views

Webpack and Lazy Load for large-scale Web Application

Background I am trying to develop with Webpack and JavaScript. Webpack would bundle all source code into one single file. When application becomes large, the file would be very large and cause ...
3
votes
3answers
172 views

Should I be lenient with types when accepting JSON data? (String vs number)

Background: So while Javascript implicitly convert various data types and hence may seem almost type-less(is there such a thing?) it does have different types. Most of my colleagues seem to think ...
2
votes
1answer
158 views

How should I structure my Observables on a Nodejs application with RxJS

So I am learning reactive programming, and I am building an app for fun that listens on various stock information tickers, and calculates specific things to show in charts etc. So right now I have ...
1
vote
1answer
215 views

Rest api manager encapsulation required or not

I am currently designing a software in which I have to use a rest client. I have decided to use a particular library, but am stuck whether I should use it directly or add a custom encapsulation layer. ...
1
vote
1answer
938 views

PHP Post vs JavaScript Ajax Request

I have been into web development with both client amd server side code, and have been using JavaScript Ajaxto receive and manipulate for data along with PHP scripts. However, I noticed that ...
3
votes
2answers
560 views

REST Api Design Patterns

I'm developing a REST Api using Node.js & Express.js. Recently I've started looking towards best practices for REST Api design but it's bit confusing so please bear with me. For Example: Lets ...
0
votes
1answer
81 views

WebApp Design: Better way of updating information in a DOM element

Background: I was working on a personal project to create an Task Checklist Web App. I worked on the code with vanilla golang and javascript. It is a very simple app with limited capability. I've used ...
0
votes
1answer
1k views

Better alternative to having a html form with select input on every row in table

I have a web application (laravel) with a page which presents a large number of rows (financial transactions) in a HTML table. On each row I want to have a drop-down (select input) allowing the user ...
0
votes
2answers
161 views

Is it acceptable to break MVC by storing data in the DOM in order to reduce load on the Database Server, ever?

I am currently using NodeJS & Express to load webpages which contain element content that is rendered via a query to MongoDB. A GET request will create Button elements, binding the MongoDB _id ...
14
votes
1answer
971 views

Does the “function returning function” pattern have a name in JavaScript?

I use this pattern quite often in JavaScript. Here is an example: const comments = [ { text: 'Hello', id: 1 }, { text: 'World', id: 4 }, ]; const byId = id => element => element.id === id; ...
5
votes
2answers
260 views

Better to send all data to client or query server for every search?

I have a search function on my site that needs to search through ~2000 items (this table never changes, it will always have the same number of items) stored in MySQL. All it needs to do is search by ...
-1
votes
1answer
719 views

coding practices: return vs else [closed]

Which coding style is considered better practice? if-return: function fn { if (condition) { /* if true: insert code here */ return; } /* ...
0
votes
2answers
4k views

Why is it uncommon (is it?) to use _ (underscore) in JS private vars?

Coming to JavaScript from C# and C/C++ world, I'm used to decorating my private members with underscore. But a couple of JS devs I know have told me it's not common in JS world, and my code looks "...
0
votes
2answers
348 views

Is it still relevant to keep script tags in the footer?

Working at a company that loads all javascript at the end of the page load. This means I can't do $(document).ready() on my page, because jquery isn't loaded (the scripts are injected into the footer ...
1
vote
2answers
85 views

JavaScript constraints on object's values

I'm currectly reading the book JavaScript: The Good Parts by Douglas Crockford. The opening of the Chapter 3 Objects immediately confuses me with a (possible) contradiction. I re-read the two ...
0
votes
1answer
149 views

In the react docs why is binding of *this* preferred over arrow functions for event handlers?

In the React docs, the constructor functions of class components contain lines where this is explicitly bound for event handlers e.g. in the docs for handling events class Toggle extends React....
1
vote
2answers
294 views

Do I need to put a license in my website's HTML and/or CSS?

I am making a website for a competition my school is taking part in, however I am not on the team and am not receiving any compensation (save for better references :P). The only condition I have set ...
1
vote
4answers
240 views

When is it justified to write implicit conditions? [duplicate]

As a rookie programmer, I've only recently been digging into benchmarking, and have been comparing various ways of accomplishing the same task in terms of speed. Most of the time, the result is ...
0
votes
1answer
162 views

Modeling JSON with Javascript

Using C# I've modeled a JSON message this way: public class MessageBase<T> { public MessageBase() { this.message = new List<T>(); } public string type { get; set; } public ...
3
votes
0answers
239 views

Redux Saga pattern for large, non-specific server responses

Our current Redux state tree is this: { "dog": { "name": "Barkley", "age": 6, "hungry": false, "location": "Living Room", "height": "36 in." }, "...
0
votes
1answer
73 views

What does the details of instantiation encapsulation mean in factory design pattern?

I am trying to understand the factory design pattern and how it can be implemented in Javascript. So far what I understood is factory design pattern helps to create an instance of more specific class ...
-1
votes
1answer
553 views

Hosting a static website containing JavaScript/jQuery

I have customized a free downloaded web template as my simple, static website. It contains HTML, CSS, and JavaScript/jQuery. I want to make it live, and am confused from where to host it. The hosting ...
0
votes
1answer
184 views

Using custom mime type for drag'n'drop events or data attribute dilema

I am having a dilema on a html/js application I have been requestyed to handle drag'n'drop events in order to display a dropped image in a div if is not from images that are already displayed in my ...