+ 1

Can't understand a question from challenge.

Hi. Can anyone explain me why is output 333? for(var i = 0; i < 3; i++) { setTimeout (function() { document.write(i) } , 200); } Thanks.

21st Jul 2017, 6:04 PM
Arev
Arev - avatar
2 odpowiedzi
+ 5
that call 3 time setTimeout(...) . but delay time is 200ms, for is ended and i have 3 value. therefore 3 time printed 3 and result is 333.
21st Jul 2017, 6:23 PM
Atiye Khajepour
Atiye Khajepour - avatar
0
but why for ends when there's something to do, I mean why don't loop waits until setTimeout's end?
21st Jul 2017, 7:33 PM
Arev
Arev - avatar