All Questions
Tagged with programming-practices javascript
42 questions
1
vote
2
answers
328
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 ...
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 ...
0
votes
3
answers
125
views
Should we test private data (static objects in this case) to make sure it maintains its structure?
I had a discussion at work about whether to unit test a private static object we're using as data for a public component.
const data = {
45: { name: 'John' },
2: { name: 'Patricia' },
27: { name: '...
11
votes
1
answer
5k
views
Is it bad practice to require the same module in multiple files in Javascript?
Let’s say I have three files, all of which import a fairly large module. But I’ve divided them because they have different functions. Now each of the JavaScript files needs an initial statement like
...
3
votes
1
answer
400
views
What is the expected performance of While loops using `array.pop()` assignment vs other methods
Recently I was asked to refactor some code that leverages JavaScript's array.reduce() method because other developers felt the code hard to read. While doing this I decided to play around with some ...
0
votes
2
answers
200
views
Should we check if the primary key exists if rendering a collection fetched from database?
I have got an argument with my colleagues about this. IMO It's common practice that you don't need to check if an id exists or not before rendering it.
So here's an example.
This is what my ...
1
vote
3
answers
4k
views
Good practice for JavaScript (ES6) data objects
I see very often to pass around unnamed data objects in JavaScript, e.g. { a: 1, b: 2}. Is it a good practice or is better to make a simple data class for that like in other languages:
class ...
2
votes
1
answer
211
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 ...
0
votes
1
answer
682
views
Why "typeof null == object" will stay in javascript?
I was reading a article about front-end development on Medium, when I stumbled upon an interesting piece of information, which is as follows:
The type of a variable can be determined by using the ...
3
votes
1
answer
158
views
What is the standard method of handling errors in a NodeJS web app?
I am currently working on a web application as a learning project, which has a NodeJS backend and uses a MongoDB database; however, I believe my question is not specific to the technologies I am using....
1
vote
2
answers
2k
views
Best Practices - Including endpoint URL calls in JavaScript vs backend calls
I am building a web application that will retrieve results from a remote server and use them to render some charts and maps. The remote server has already been implemented and contains a large amount ...
1
vote
0
answers
1k
views
What are the best practices for picking selectors for web scrappers?
The following is an example using https://github.com/GoogleChrome/puppeteer
'use strict';
const puppeteer = require('puppeteer');
(async() => {
// const browser = await puppeteer.launch();
// ...
17
votes
4
answers
7k
views
Why does Facebook obfuscate the names of CSS classes?
If you look at the source code of a website such as Facebook, you'll see many classes as such:
<div class="_cy6 _2s24"><div class="_4kny"><div class="uiToggle _8-a _1kj2 _4d1i _-57 _5-...
-1
votes
1
answer
331
views
Modelling research paper data in JSON
I need to design an UI to edit a research paper, I don't have enough knowledge about the research domain but still I tried to do my best and thought to design a normalized schema. I am describing the ...
1
vote
0
answers
85
views
Capturing keyboard events for a limited time
I'm trying to code a kind of simple video game where there are two kind of players:
Human Players: They enter an keyboard input
CPU Players: A random input is calculated
For Human Players there is a T ...