Recall & Review
beginner Click to reveal answer
What does the
break statement do in JavaScript loops?The
break statement immediately stops the loop and exits it, skipping any remaining iterations.beginner Click to reveal answer
Can
break be used outside of loops in JavaScript?No,
break is used only inside loops (for, while, do-while) or switch statements to exit them early.intermediate Click to reveal answer
What happens if you use
break inside a nested loop?The
break statement only exits the innermost loop where it is used, not all outer loops.beginner Click to reveal answer
Example: What will this code output?<br><pre>for(let i = 0; i < 5; i++) {<br> if(i === 3) break;<br> console.log(i);<br>}</pre>It will print:
0
1
2
Because when
0
1
2
Because when
i becomes 3, the break stops the loop immediately.beginner
Click to reveal answer
How does
break differ from continue in loops?break stops the entire loop immediately.continue skips only the current iteration and moves to the next one.What does the
break statement do inside a loop?✗ Incorrect
break immediately stops the loop and exits it.Where can you use the
break statement in JavaScript?✗ Incorrect
break is valid inside loops and switch statements.What happens if
break is used inside nested loops?✗ Incorrect
break exits only the loop where it is used, usually the innermost one.What will this code print?
for(let i=0; i<3; i++) { if(i===1) break; console.log(i); }✗ Incorrect
When i is 1,
break stops the loop, so only 0 is printed.How is
break different from continue?✗ Incorrect
break stops the loop; continue skips only the current iteration.Explain how the
break statement works inside a loop and give a simple example.Think about when you want to stop repeating something early.
You got /3 concepts.
Describe the difference between
break and continue in loops.One stops all, the other skips one.
You got /3 concepts.
