0

I am unable to understand why this code prints 6, when it is supposed to print 1-5 with an interval of 1 s.

 function x(){
 for(var i = 1; i <= 5; i++){
   setTimeout(function () {
    console.log(i);
   }, i*1000);
 }
}
x();
User12
  • 21
  • 6

0 Answers0