Loops let you repeat a block of code multiple times and for loop is one of the most commonly used types of loop in JavaScript. They follow three key parts; the initialising expression, condition, and incrementing expression separated by semi colons within parentheses after the keyword for.
for (initialisingExpression; condition; incrementingExpression) {
// code to repeat
}
- initialisingExpression: runs once at the beginning (e.g., let i = 0)
- condition: evaluated before each loop; if true, the loop runs
- code block: runs if the condition is true
- incrementingExpression: runs after the code block each time
- Repeats until the condition is false
- Then the program moves on to any code outside the loop
for (let i = 1; i <= 10; i++) {
console.log(i);
}