1. Use dot notation when accessing properties.
3. Use the exponentiation operator ** when calculating exponentiations.
const luke = { jedi: true, age: 28, }; // bad const isJedi = luke['jedi']; // good const isJedi = luke.jedi;2. Use bracket notation [ ] when accessing properties with a variable.
const luke = {
jedi: true,
age: 28,
};
function getProp(prop) {
return luke[prop];
}
const isJedi = getProp('jedi');
// bad const binary = Math.pow(2, 10); // good const binary = 2 ** 10;
Best Practices
JavaScript
Comments
Post a Comment