I just have a curiosity about the difference between using var and let when assigning variables.
for(var i = 0; i < 4; i++){
setTimeout(() => console.log(i), 1000);
}
output: 4
4
4
4
for(let i = 0; i < 4; i++){
setTimeout(() => console.log(i), 1000);
}
output: 0
1
2
3
From the above code snippets, I wonder why those two codes log different results.