0
for (var i=1; i<=5; i++) {
  setTimeout( function timer(){
    console.log( i );
  }, i*1000 );
}

Even if the function passed to setTimeout as an argument doesn't create a new scope, being an entry controlled loop, why does the above code output to 6 & not 5 for each iteration ?

Dev P
  • 118
  • 11

0 Answers0