Dot Notation
Use dot notation when accessing properties.
ESLint: dot-notation
Examples
⇣ Incorrect code for this rule:
const snowball = {
density: 20,
falling: true
};
const isFalling = snowball["falling"];
⇡ Correct code for this rule:
const snowball = {
density: 20,
falling: true
};
const isFalling = snowball.falling;
Bracket Notation
Use bracket notation []
when accessing properties with a variable.
Examples
⇣ Incorrect code for this rule:
const snowball = {
density: 20,
falling: true
};
function getProp(prop) {
return snowball[prop];
}
const isFalling = getProp("falling");
Exponentiation Operator
Use exponentiation operator **
when calculating exponentiations.
ESLint: no-restricted-properties
Examples
⇣ Incorrect code for this rule:
const binary = Math.pow(2, 10);
⇡ Correct code for this rule:
const binary = 2 ** 10;