I have a very trivial question. For a simple loop with setTimeout, like this:
for (var count = 0; count < 3; count++) { setTimeout(function() {
That is because by the time the for loop completes its execution the count is 3, and then the set timeout is called.
Try this:
var count = 0; setTimeout(function() { for (count = 0; count < 3; count++) { alert("Count = " + count); } }, 1000* count);