for, while, do...while, and for...of repeat work. for...in iterates object keys (avoid on arrays).
Prefer for...of
for (const item of array) is clear for values. Classic for (let i=0; ...) when you need index.
break and continue
Exit loop early or skip to next iteration—use sparingly for clarity.
Important interview questions and answers
- Q: for...in on array?
A: Iterates keys as strings—including holes—usually wrong for arrays. - Q: Infinite loop risk?
A: while without advancing condition—always mutate loop variable.
Self-check
- When for...of vs classic for?
- What does continue do?
Tip: Re-run the playground code for loops-for-while and tweak one line before the MCQs.
Interview prep
- for...of?
Iterate array values cleanly.