Skip to content

JS For Loop

Syntax

The for loop in JavaScript repeats a block of code a specific number of times, based on an initialization, condition, and iteration expression.

for (initialization; condition; increment) {
// Code to execute
}

Example

for (let i = 1; i <= 5; i++) {
console.log(i);
}
// Output:
// 1
// 2
// 3
// 4
// 5