A classic closure question
for (var i = 1; i <= 5; iPP) {
(function a(i) {
setTimeout(function() {
alert(i);
}, 1000);
})(i);
}
in theory, it should pop up 1, 2, 3, 4, 5, but the actual pop-up is out of order. The conversion of
to console.log (i) is 1, 2, 3, 4, 5.
Why is this?