Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015년 7월.
레이블 구문은 break나 continue 구문과 함께 사용할 수 있다. 원하는 식별자로 구문 앞에 레이블을 추가할 수 있다.
참고 : 레이블을 붙인 반복문이나 블록가 자주 사용되는 것은 아니다. 반복문으로 점프하는 대신에 함수를 호출할 수도 있다.
JavaScript에서 사용할 수 있는 식별자면 모두 가능하다.
statement구문. break는 모든 레이블 구문에서 사용될 수 있으며, continue는 반복 레이블 구문에서만 사용할 수 있다.
반복문에 레이블을 붙이고, break나 continue 구문을 사용해 반복문의 어느 위치에서 작업을 멈추고 어느 위치에서 다시 수행할지를 알려줄 수 있다.
JavaScript에는 goto 구문이 없다는 것에 주의. break나 continue에서만 레이블을 사용할 수 있다.
strict mode 코드에서 "let"을 레이블 이름으로 사용할 수 없다. SyntaxError를 발생시킨다. (let은 허용되지 않는 식별자이다.)
items, tests 배열을 보면 이 예제는 tests를 통과하는 items의 수를 세고 있다.
items, tests 배열을 보면, 다음 예제는 items가 tests를 모두 통과하는지 판단한다.
간단한 블록에도 레이블을 사용할 수 있지만, 반복문 아닌 레이블에는 break문만 사용할 수 있다.
ECMAScript 2015에서, 레이블 붙인 함수 선언문은 web compatibility annex of the specification의 non-strict 모드에서 표준화되어 있다.
strict mode 에서는 SyntaxError를 발생시킨다.
Generator functions는 strict code도 non-strict code에서도 레이블 붙일 수 없다.
| ECMAScript® 2027 Language Specification # sec-labelled-statements |
Enable JavaScript to view this browser compatibility table.
This page was last modified on 2024년 12월 17일 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.