[ad_1]
Asked
Viewed
8 times
Can someone explain me the logic behind var and let in this situation?
for(let i=0; i<5;i++) {
setTimeout(() => {
console.log(i);
}, 1000);
}
Prints 0 1 2 3 4
for(var i=0; i<5;i++) {
setTimeout(() => {
console.log(i);
}, 1000);
}
Prints 5 5 5 5 5 5
0
lang-js
[ad_2]