for (var i = 0; i < 5; i++) {
console.log(`Inside the loop: ${i}`);
}
console.log(`Outside the loop: ${i}`);
output:
Inside the loop: 0
Inside the loop: 1
Inside the loop: 2
Inside the loop: 3
Inside the loop: 4
Outside the loop: 5
In this example, the i
variable is a global variable. Therefore, it can be accessed from both inside and after the for loop.