for (var i = 0; i < 5; i++) { setTimeout(function () { console.log(i); }, 1000); } Code language: JavaScript (javascript)