<!DOCTYPE html> <html> <head> <title></title> <script type="text/javascript"> for(var i = 0 ; i < 10; i++){ setTimeout((function(i){ return function(){ console.log(i);} })(i), i*1000); } </script> </head> <body> </body> </html>