일관된 들여쓰기(Indentation) - 2 스페이스 사용

// 👎 Bad
function example() {
    console.log('Hello, world!');
}

// 👍 Good
function example() {
  console.log('Hello, world!');
}

매함수의 매개변수는 최대 4개로 한정하도록 한다.

// 👎 Bad
function example(a, b, c, d, e) {
  // code
}

// 👍 Good
function example(a, b, c, d) {
  // code
}

함수는 250 라인을 넘지 않도록 한다. 단, Template 설정 시에는 이를 별도로 표기한다.

// 👎 Bad
function largeFunction() {
  // 300 lines of code
}

// 👍 Good
function smallerFunction() {
  // 100 lines of code
}

function anotherFunction() {
  // 150 lines of code
}

한 라인에 120자를 넘지 않는다.

// 👎 Bad
const example = 'This is a very long string that exceeds the maximum line length of 120 characters and should be broken into multiple lines for better readability.';

// 👍 Good
const example = 'This is a very long string that exceeds the maximum line length of 120 characters and should be ' +
  'broken into multiple lines for better readability.';

Operator 주위에 공백을 둔다. 예) a+b à a + b

// 👎 Bad
const sum = a+b;

// 👍 Good
const sum = a + b;

단어 주위에 공백을 둔다.

// 👎 Bad
if(a===b){
  // code
}

// 👍 Good
if (a === b) {
  // code
}

함수 범위 내에서 if, else, for단어의 앞과 뒤에 공백을 둔다.

// 👎 Bad
if(a===b){
  for(let i=0;i<10;i++){
    // code
  }else{
    // code
  }
}

// 👍 Good
if (a === b) {
  for (let i = 0; i < 10; i++) {
    // code
  } else {
    // code
  }
}

switchwhile은 바로 다음에 “(“를 사용한다.

// 👎 Bad
switch (x) {
  // code
}

while (x < 10) {
  // code
}

// 👍 Good
switch(x) {
  // code
}

while(x < 10) {
  // code
}

bool 값을 반환하는 함수 이름은 is 혹은 has로 시작합니다.

// 👎 Bad
function checkValid() {
  return true;
}

// 👍 Good
function isValid() {
  return true;
}

function hasItems() {
  return true;
}

파일 이름명은 언더바(_)로 시작하지 않는다.

// 👎 Bad
_example.js

// 👍 Good
example.js