This question has already been answered:
var count = 0; for ( var i = 0; i < 4; i++ ) { setTimeout( function(){ assert( i == count++, "Check the value of i." ); }, i * 200); } Please explain how this code works. Why does the loop run four times with a value of 4?
assertin JS. What does she do, explain ... - Rulesi), doesn't it? He needs to use them correctly . - VladDiis in closure with respect to the function that is passed tosetTimeout- Specter