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.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3b1aa-412aa.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3b1aa-412aa.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?