let: code block
const: cannot change anymore
{} shoule be clear
1. avoid magic number
if (password.length < 8 ) {
}
VS
const MIN_PASSWORD_LENGTH = 8;
if (password.length < MIN_PASSWORD_LENGTH ) {
}
const SECONDS_IN_A_DAY = 86400;
setTimout( function, 86400 SECONDS_IN_A_DAY)
2 avoid addtional context
03. Use default arguments instead of short circuits.
function calculateDiscount(discount = 10){
}
04. Restrict function arguments to three(3).
05. Function should do one thing.
06. Avoid Boolean flags as parameters.
07. Encapsulate conditionals. function shouldDisplayLoader
08. Avoid contractions while naming.
09. Use a prefix when naming Boolean variables (i.e is*,has*)
10. Use a verb when naming functions(get, set,reset,fetch,remove,delete and handle etc).