DEV Community

Discussion on: 10 Practical JavaScript Tricks

Collapse
 
ikoshelev profile image
IKoshelev • Edited

Sorry to point this out, but about half of this advice are bad.

3 hungry && goToFridge() - no. Your code is written once and then read 10 times. This makes it harder to read.

4 And now you can't have 0... Use default args.

function doSomething(arg1 = 32){ 
//....
}

If you are dealing with variables - use nullish coalescing operator.

a = a ?? 32;

5 'Coma operator' - don't use it as described ever. It is a constant source of bugs.

6 'Using length to resize an array' - try avoiding this. It is a hack that hides intentions and leads to bugs.

P.S.
1

const args = Array.from(arguments); // just make sure to polyfil if you expect older browsers