1

This code display 10 ten times.

But I want to display numbers from 0 to 9.

How can I fix this code?

for(var i = 0; i < 10; i++) {
    setTimeout(function() {
      console.log(i);  
    }, 10);
}
John Doe
  • 3,794
  • 9
  • 40
  • 72
  • Duplicate. This should answer your question: [SO](http://stackoverflow.com/questions/750486/javascript-closure-inside-loops-simple-practical-example) – Whothehellisthat Mar 08 '17 at 22:08

0 Answers0