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