2

when I print "i" inside setTimeout with time diff 0. why does it print "n" the same number always?

for(i = 0; i < 5; i++) {
   setTimeout(function() {console.log(i)}, 0);
}

Output:

5
5
5
5
5
Kishan Rajdev
  • 1,839
  • 1
  • 14
  • 22

0 Answers0