32 ms·
Thought so as well first. But then again, you can write for (let i=0; i<10; i++) { console.log(i); i++; } And it correctly logs "1 3 5 7 9". So i
by xg15 5y ago
Thought so as well first. But then again, you can write
for (let i=0; i<10; i++) {
console.log(i);
i++;
}
And it correctly logs "1 3 5 7 9".
So if anything, the desugaring would have to be something like
for (var _i=0; _i<3; _i++) {
let i = _i;
setInterval(() => {console.log(i); i+=100}, 1000);
_i = i;
}
Haven't tried out putting closures inside the condition or incrementer to see if things get even weirder.