break
In JavaScript, the break keyword ends the innermost loop or switch statement that contains it, and execution continues with the statement after that loop or switch. In a switch, it stops execution from falling through into the next case. To skip only the rest of the current pass and keep looping, code uses continue instead.
A break can also name a label, which is an identifier and a colon placed before a statement. The break label; form exits the labeled statement, so code can leave an outer loop from inside a nested one. The labeled statement can be any statement, including a plain block. Labels aren’t keywords, and the label must be on the same line as break.
A break can’t cross a function boundary. One inside a callback, such as the function passed to .forEach(), is a SyntaxError, even when the call sits inside a loop.
JavaScript break Keyword Syntax
A break statement can appear with or without a label:
break;
break <label>;
JavaScript break Keyword Examples
A break statement ends the loop as soon as a reading is negative:
> const readings = [12, 18, -1, 25];
undefined
> for (const value of readings) {
… if (value < 0) {
… break;
… }
… console.log(value);
… }
12
18
undefined
The loop stops at the first negative reading, so it never reaches 25.
With a label, break exits both loops at once:
> const grid = [
… [1, 2, 3],
… [4, 5, 6],
… ];
undefined
> search: for (const row of grid) {
… for (const cell of row) {
… if (cell === 5) {
… console.log("Found 5");
… break search;
… }
… }
… }
Found 5
undefined
JavaScript break Keyword Use Cases
- Stopping a loop once the item it’s looking for is found
- Ending a
while (true)loop when an exit condition holds - Preventing fall-through between
caseclauses in aswitch - Exiting nested loops at once with a labeled
break
Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.
By Leodanis Pozo Ramos • Updated Nov. 4, 2026