Search for a command to run...
Why var prints 3 3 3 and let prints 0 1 2
One shared binding for the var loop
var i is function-scoped: the loop creates exactly one variable, and all three callbacks will close over that one.
Execution
1for (var i = 0; i < 3; i++) {//i: 02 setTimeout(() => console.log('var i =', i), 0);3}4 5for (let j = 0; j < 3; j++) {6 setTimeout(() => console.log('let j =', j), 0);7}8 9console.log('sync done, i =', i);