Key Ideas
1Why We Need Loops. Imagine you want to print the numbers 1 through 100. Without loops, you'd write console.log(1), console.log(2), all the way to console.log(100) — 100 separate lines. T...
2The for Loop. The for loop is the workhorse of JavaScript iteration. It packs initialization, condition, and update all into one concise line, making it easy to read when you know e...
3The while Loop. The while loop is the right choice when you don't know in advance how many iterations you need. You simply provide a condition, and the loop keeps running as long as t...
4The do...while Loop. The do...while loop is like a while loop with one crucial difference: it always executes the body at least once, then checks the condition. The condition check comes a...
5The for...of Loop. Introduced in ES6, for...of is the modern, clean way to iterate over iterable values — arrays, strings, Sets, Maps, and NodeLists. Instead of managing an index counter...