Properties

Dot notations

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');

results matching ""

    No results matching ""