JavaScript Style Guide - Properties

Jang Seok Woo·2022년 8월 11일
0

실무

목록 보기
109/136

12. Properties

12.1 Use dot notation when accessing properties.

eslint: dot-notation

const luke = {
  jedi: true,
  age: 28,
};

// bad
const isJedi = luke['jedi'];

// good
const isJedi = luke.jedi;

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

12.3 Use exponentiation operator ** when calculating exponentiations.

eslint: no-restricted-properties.

// bad
const binary = Math.pow(2, 10);

// good
const binary = 2 ** 10;

출처 : https://github.com/airbnb/javascript

profile
https://github.com/jsw4215

0개의 댓글