JavaScript Best Practices
Operators and comparison
Ternary operators
Ternary operators should be put on a single line:
let status = (age >= 18) ? 'adult' : 'minor';
Not nested:
let status = (age >= 18) ? 'adult' : 'minor';
This is much harder to read.
Use strict equality
Always use strict equality and inequality.
Do this:
name === 'Chris'; age !== 25;
Not this:
name == 'Chris'; age != 25;
Use shortcuts for boolean tests
Use shortcuts for boolean tests – use x
and !x
, not x === true
and x === false
.