본문 바로가기

개발/Javascript

블록(Blocks)

블록(Blocks)

  • Use braces with all multi-line blocks.

  • 복수행의 블록에는 중괄호 ({}) 를 사용해 주십시오.

    // bad
    if (test)
      return false;
    
    // good
    if (test) return false;
    
    // good
    if (test) {
      return false;
    }
    
    // bad
    function() { return false; }
    
    // good
    function() {
      return false;
    }
  • If you're using multi-line blocks with if and else, put else on the same line as your if block's closing brace.

  • 복수행 블록의 if 와 else 를 이용하는 경우 else 는 if 블록 끝의 중괄호(})와 같은 행에 위치시켜 주십시오.

    // bad
    if (test) {
      thing1();
      thing2();
    }
    else {
      thing3();
    }
    
    // good
    if (test) {
      thing1();
      thing2();
    } else {
      thing3();
    }


'개발 > Javascript' 카테고리의 다른 글

공백(Whitespace)  (0) 2018.03.11
코멘트(Comments)  (0) 2018.03.11
프로퍼티(Properties)  (0) 2018.03.11
Arrow함수(Arrow Functions)  (0) 2018.03.11
조건식과 등가식(Comparison Operators & Equality)  (0) 2018.03.11