Airbnb 코드컨벤션 주소

https://github.com/parksb/javascript-style-guide

Airbnb 코드컨벤션

// bad
const obj = {
  lukeSkywalker: lukeSkywalker,
};

// good
const obj = {
  lukeSkywalker,
};
// bad
const len = items.length;
const itemsCopy = [];
let i;

for (i = 0; i < len; i++) {
  itemsCopy[i] = items[i];
}

// good
const itemsCopy = [...items];
const arr = [1, 2, 3, 4];

// bad
const first = arr[0];
const second = arr[1];

// good
const [first, second] = arr;
// bad
function processInput(input) {
  return [left, right, top, bottom];
}

const [left, __, top] = processInput(input);

// good
function processInput(input) {
  return { left, right, top, bottom };
}

const { left, right } = processInput(input);
// really bad
function handleThings(opts) {
  opts = opts || {};
  // handleThings() 호출 시 파라미터가 전달되면 opts에 저장, 없으면 빈 객체({})
}

// good
function handleThings(opts = {}) {
  // 함수 선언 시 default 값을 저장
}