Here's the code snippet I'm working with:
for (var i = 1; i <= 5; i++) {
setTimeout(function () {
console.log(i);
}, 1000);
}
I'm confused about the output of this code. When I run it, I see the number 6 printed in the console five times. However, if I change the variable declaration to use `let` instead of `var`, I get the expected output of 1, 2, 3, 4, 5 each after one second. Why does this happen?