JS closure question: why is this for loop printed every other second

this is a problem related to js closures

for (let i = 0; i < 5; iPP) {
    setTimeout(function() {
        console.log(i)
    }, 1000 * i)
}

Why is the 1000 millisecond of

setTimeout 1000 milliseconds except for the first time 0 milliseconds, and why is I always 1?

Sep.05,2021

setTimeout (fn, timer) is a timer, that is, register a function fn , timer (not necessarily exactly the same) and execute.
for this question, it is equivalent to registering five timers, which are 0s, 1s, 2s, 3s, and then execute the corresponding fn --> function () {console.log (i)} , so the effect is to print every other second.

Menu