0
0
Javascriptprogramming~5 mins

Break statement in Javascript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the break statement do in JavaScript loops?
The break statement immediately stops the loop and exits it, skipping any remaining iterations.
Click to reveal answer
beginner
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.
Click to reveal answer
intermediate
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.
Click to reveal answer
beginner
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:<br>0<br>1<br>2<br>Because when i becomes 3, the break stops the loop immediately.
Click to reveal answer
beginner
How does break differ from continue in loops?
break stops the entire loop immediately.<br>continue skips only the current iteration and moves to the next one.
Click to reveal answer
What does the break statement do inside a loop?
ASkips the current iteration and continues
BStops the loop immediately and exits it
CRestarts the loop from the beginning
DDoes nothing special
Where can you use the break statement in JavaScript?
AOnly inside functions
BAnywhere in the code
CInside loops and switch statements
DOnly inside if statements
What happens if break is used inside nested loops?
AIt causes an error
BIt exits all loops
CIt skips the current iteration
DIt exits only the innermost loop
What will this code print?<br>
for(let i=0; i<3; i++) { if(i===1) break; console.log(i); }
A0
B0 1
C1 2
D0 1 2
How is break different from continue?
A<code>break</code> stops the loop; <code>continue</code> skips current iteration
B<code>break</code> skips current iteration; <code>continue</code> stops the loop
CBoth do the same thing
DNeither affects the loop
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.