This question has already been answered:
Who can explain why the number 10 is displayed 10 times, and not in order. I know that the timer is first added to the queue, and then I don’t know what is going on.
for (var i=0; i<10; i++) { setTimeout('alert(i)', 1000); }
for (var i = 0; i < 10; i++) { setTimeout('alert(' + i + ')', 1000); }for (var i = 0; i < 10; i++) { setTimeout('alert(' + i + ')', 1000); }- Igor