JavaScript Labeled statement Statement
A labeled statement gives a name to a loop or block, so break or continue can refer to it, for example to exit an outer loop.
Description
A label is an identifier followed by a colon, placed before a statement. break label and continue label can then target that statement, which is mainly useful for exiting or continuing an outer loop from inside a nested one. Labels are rare; moving the loops into a function and using return is often clearer.
Labels can only be referenced by break and continue statements inside the labeled statement. continue can only target a label on a loop, while break can also target a labeled block, which lets you jump out of a block early. Label names follow the same rules as variable names and live in their own namespace, so they don't clash with variables.
Because labeled jumps are uncommon, many developers find them surprising to read. Before reaching for a label, consider whether moving the nested loops into a function and using return, or using an array method such as some() or find(), would express the intent more clearly.
Syntax
label:
statementExample
Browser Support
The following information will show you the current browser support for the Labeled statement statement. Hover over a browser icon to see the version that first introduced support for this statement.
Desktop





Tablets & Mobile





