The labeled statement can be used with break or continue statements. It is prefixing a statement with an identifier which you can refer to.

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.

Note: Labeled loops or blocks are very uncommon. Usually function calls can be used instead of loop jumps.

Syntax

label :
statement

label

Any JavaScript identifier that is not a reserved word.

statement

A JavaScript statement. break can be used with any labeled statement, and continue can be used with looping labeled statements.

Description

You can use a label to identify a loop, and then use the break or continue statements to indicate whether a program should interrupt the loop or continue its execution.

Note that JavaScript has nogoto statement, you can only use labels with break or continue.

In strict mode code, you can't use "let" as a label name. It will throw a SyntaxError (let is a reserved identifier).