Get to know MDN better
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The break statement terminates the current loop or switch statement and transfers program control to the statement following the terminated statement. It can also be used to jump past a labeled statement when used within that labeled statement.
Identifier associated with the label of the statement to break to. If the break statement is not nested within a loop or switch, then the label identifier is required.
When break; is encountered, the program breaks out of the innermost switch or looping statement and continues executing the next statement after that.
When break label; is encountered, the program breaks out of the statement labeled with label and continues executing the next statement after that. The break statement needs to be nested within the referenced label. The labeled statement can be any statement (commonly a block statement); it does not have to be another loop statement.
A break statement, with or without a following label, cannot be used at the top level of a script, module, function's body, or static initialization block, even when the function or class is further contained within a loop.
The following function has a break statement that terminates the while loop when i is 3, and then returns the value 3 * x.
The following code has a break statement that terminates the switch statement when a case is matched and the corresponding code has run.
The following code uses break statements with labeled blocks. By using break outerBlock, control is transferred to the end of the block statement marked as outerBlock.
A break statement must be nested within any label it references. The following code also uses break statements with labeled blocks, but generates a syntax error because its break statement references block2 but it's not nested within block2.
Syntax errors are also generated in the following code examples which use break statements within functions that are nested within a loop, or labeled block that the break statements are intended to break out of.
| ECMAScript® 2027 Language Specification # sec-break-statement |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Jul 8, 2025 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.