for (let i = 1; i <= 5; ++i) { setTimeout(function(){ console.log(i); }, 1000); } let will create block level scope and it will work fine.
for (let i = 1; i <= 5; ++i) {
setTimeout(function(){
console.log(i);
}, 1000);
}
let will create block level scope and it will work fine.