Loops and iteration
Loops and iteration
Use for when you need an index or counter, while when repetition depends on a condition, and for...of to iterate values from an iterable. Ensure loop conditions eventually become false to avoid infinite loops.
Try it yourself
Change the example, run it, and explain the result in your own words. Then create one variation of your own.
Key idea
Use the example as a starting point, not something to memorize. Practise, inspect the result and make small improvements.
Code example
const topics = ["HTML", "CSS", "JavaScript"];
for (const topic of topics) { console.log(topic); }