Variables
- Use const unless mutability is necessary, in which case var and let are permissible
- Use camelCase naming for local variables
- Use MACRO_CASE for naming constants
- NO MAGIC NUMBERS
String literals
- Use double quotes instead of single quotes for String primitives
Functions
- Use lambda expressions instead of functions unless necessary
- Use ES6 arrow functions instead of the function keyword
// prefer this
const bar = (foo) => {
return 0;
};
// over this
function baz(foo) {
return 0;
}
Semicolons
- End all statements that can end with semicolons with semicolons.
Indentation
- Use two spaces for indentation
Functions () and {}
if () {
// etc
}
Miscellaneous
// have one space between operators and operands
const a = 1 + 3 * sqrt(4);
// start the else on a new line
// add spaces between keywords and the open parenthesis
if (true) {
// don't add a space between the identifier and the open parenthesis
bar();
}
else {
baz();
}