Properties
Dot notations
- Use dot notation when accessing properties. eslint:
dot-notation
jscs:requireDotNotation
const luke = {
jedi: true,
age: 28,
};
// bad
const isJedi = luke['jedi'];
// good
const isJedi = luke.jedi;
Subscript notation
- Use subscript notation
[]
when accessing properties with a variable. - Use subscript notation when properties is dynamic
const luke = {
jedi: true,
age: 28,
};
function getProp(prop) {
return luke[prop];
}
const isJedi = getProp('jedi');