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,919
  • 3
  • 18
  • 24

0 Answers0