Predict break Output
Predict Output Medium
Question
What does this code print?
Code
for (let i = 1; i <= 5; i++) {
if (i === 3) {
break;
}
console.log(i);
}
Hint
break exits the loop immediately.
Explanation
The loop starts with i=1 (prints 1), then i=2 (prints 2), then i=3 — the if condition is true, so break exits the loop before printing. Values 4 and 5 are never reached. Output: 1, 2 (each on its own line).
Related Resources
Related Lessons
- Loops (for & while)
Learn how for and while loops work.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.