JavaScript Semicolon (세미콜론)
프로그래밍/JavaScript 2013. 12. 6. 09:42 |http://www.w3schools.com 에는 대략 이렇게 쓰여져 있다.[1]
Semicolon ;
Semicolon separates JavaScript statements.
Normally you add a semicolon at the end of each executable statement.
Using semicolons also makes it possible to write many statements on one line.
![]() | You might see examples without semicolons. Ending statements with semicolon is optional in JavaScript. |
---|
자바스크립트엔 auto semicolon insertion(ASI) 가 동작하며, 세미콜론을 붙이지 않아도 자동으로 들어간다.
또한 ASI 로 인해서 공백문자(특히 newline)도 중요해진다. [2]
c/java 등에서 연산자 우선순위를 신경쓰지 않고 괄호를 사용하듯이
자바스크립트에서 ASI 규칙에 의존하기 보단 세미콜론을 항상 다는 것이 이롭다.
http://en.wikipedia.org/wiki/JavaScript_syntax
위 링크에 이와 관련한 자바스크립트 문법 예제가 몇 있다.
한 가지 예를 보자면
대략 이런 일이 일어날 수도 있다.
ASI 의 원리를 대략 이해하고, 들여쓰기 등의 규칙을 절대적으로 준수하고 세미콜론을 항상 붙이자.
references :