break vs continue
By FrontendPro Editorial Team Updated 9/26/2026
Answer
break leaves the loop entirely. continue skips the rest of the current iteration and moves to the next one.
for (const n of [1, 2, 3, 4, 5]) {
if (n === 3) break; // stops at 3 → logs 1, 2
console.log(n);
}
for (const n of [1, 2, 3, 4, 5]) {
if (n === 3) continue; // skips only 3 → logs 1, 2, 4, 5
console.log(n);
}
break in a switch
Here it means something slightly different: it ends the switch, preventing fall-through into the next case. Forgetting it is a classic bug:
switch (type) {
case "a": doA(); // no break — execution falls into "b"
case "b": doB(); break;
}
They only affect the innermost loop
To exit an outer loop from inside a nested one, use a label:
outer:
for (const row of rows) {
for (const cell of row) {
if (cell === target) break outer; // leaves both loops
}
}
Labels are rare and often a sign the loop should be a function with an early return, which reads better.
They do not work in forEach
items.forEach((x) => { if (x === 3) break; }); // SyntaxError
items.forEach((x) => { if (x === 3) return; }); // acts like continue, not break
return inside forEach only skips the current item; there is no way to stop early. Use for...of when you need break, or pick the method that already means "stop at the first match":
const found = items.find((x) => x.id === id); // stops as soon as it matches
const hasAny = items.some((x) => x.active); // stops at the first true
Choosing find, some or every usually expresses the intent better than a loop with a break in it.
