Properties

  • 12.1 Use dot notation when accessing properties. eslint: dot-notation

    1. const luke = {
    2. jedi: true,
    3. age: 28,
    4. };
    5. // bad
    6. const isJedi = luke['jedi'];
    7. // good
    8. const isJedi = luke.jedi;

  • 12.2 Use bracket notation [] when accessing properties with a variable.

    1. const luke = {
    2. jedi: true,
    3. age: 28,
    4. };
    5. function getProp(prop) {
    6. return luke[prop];
    7. }
    8. const isJedi = getProp('jedi');

  • 12.3 Use exponentiation operator ** when calculating exponentiations. eslint: no-restricted-properties.

    1. // bad
    2. const binary = Math.pow(2, 10);
    3. // good
    4. const binary = 2 ** 10;