in page interview/js2.html (Closures Inside Loops part), the Solution code is
for(var i = 0; i < 10; i++) {
setTimeout((function(i) {
console.log(i);
})(i), 10)
}
but in this solution, the setTimeout's milliseconds set not work, because you use the IIFE (Immediately Invoked Function Expression), and should become
for(var i = 0; i < 10; i++) {
setTimeout((function(i) {
return function() { console.log(i) }; //return a new function
})(i), 10)
}
in page interview/js2.html (Closures Inside Loops part), the Solution code is
but in this solution, the setTimeout's milliseconds set not work, because you use the IIFE (Immediately Invoked Function Expression), and should become