empty 문은 JavaScript 아무것도 동작하지 않습니다.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
구문
;
설명
empty statement은 JavaScript구문에 하나가 필요할 때 어떤 문도 실행되지 않을 것이라는 것을 나타내는 세미 콜론(;)입니다. 여러개의 문장을 원하지만 JavaScript는 block statement을 사용하여 하나만 허용하며 여러개의 문장을 하나로 결합합니다.
예제
빈 문은 루프 문과 함께 사용되기도합니다. 빈 루프 본문이있는 다음 예제를 참조하십시오.
var arr = [1, 2, 3]; // Assign all array values to 0 for (i = 0; i < arr.length; arr[i++] = 0) /* empty statement */ ; console.log(arr) // [0, 0, 0]
참고: 정상적인 세미 콜론을 구분하는 것이 그리 쉽지 않기 때문에, empty statement를 사용할 때는 의도적으로 주석을 달아주는것이 좋습니다. 다음 예 에서는 의도한대로 코드가 동작하지 않을것입니다. 아마도 killTheUniverse()를 if문 안에서 실행하고자 했던것 같습니다.
if (condition); // Caution, this "if" does nothing! killTheUniverse() // So this always gets executed!!!
다른 예 : 중괄호 ({})가없는 if...else 문에서 three가 true이면 아무 일도 일어나지 않고 four를 건너 뛰고 else case의 launchRocket() 함수도 실행되지 않습니다.
if (one) doOne(); else if (two) doTwo(); else if (three) ; // nothing here else if (four) doFour(); else launchRocket();
명세
브라우저 호환성
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Empty statement (;) | Chrome Full support 3 | Edge Full support 12 | Firefox Full support 1 | IE Full support 3 | Opera Full support 3 | Safari Full support 5 | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 10.1 | Safari iOS Full support 4.2 | Samsung Internet Android Full support 1.0 | nodejs Full support 0.1.100 |
Legend
- Full support
- Full support