The JavaScript break statement
The break statement immediately exits the nearest enclosing loop or switch. In a loop, it stops iterating right away — useful for ending a search once you've found a match. In a switch, it stops fall-through after a case. Use continue to skip just one iteration instead.
Overview
break jumps out of a loop or switch entirely, the moment it runs. In a for or while loop, it's how you stop early — once you've found the item you were searching for, there's no point checking the rest, so break ends the loop and execution continues after it.
In a switch, break plays a different but related role: it stops fall-through after a matching case, so execution doesn't spill into the following cases. Forgetting it there is a classic bug.
It's easy to confuse with two relatives. continue skips only the current iteration and moves to the next — it doesn't leave the loop. return exits the whole function, not just the loop. By default break exits only the innermost loop; to break out of nested loops at once, you can label the outer loop and write break outerLabel. That said, array methods like find() or some() often express "stop at the first match" more clearly than a manual break.
Syntax
for (const item of items) {
if (item === target) {
break; // stop the loop now
}
}
// labeled break (exits the outer loop)
outer: for (...) {
for (...) { break outer; }
}
Example
<pre id="out" style="font:15px ui-monospace,monospace"></pre>
<script>
const nums = [4, 8, 15, 16, 23, 42];
let found = null;
for (const n of nums) {
if (n > 15) { found = n; break; } // stop at first > 15
}
document.getElementById('out').textContent = 'first over 15: ' + found; // 16
</script>
Best practices
Frequently asked questions
What does break do in JavaScript?
What is the difference between break and continue?
break exits the loop entirely; continue skips the rest of the current iteration and moves to the next.How do I break out of a nested loop?
break label: outer: for (...) { for (...) { break outer; } }.What is the difference between break and return?
break exits only the loop or switch; return exits the entire function.