Here are the two code snippets, I am using "var" keyword in one and "let" in another. why the outcomes are so different.
for (let i = 0; i < 5; i++) {
setTimeout(function() {
console.log(i);
}, 100);
}
for (var i = 0; i < 5; i++) {
setTimeout(function() {
console.log(i);
}, 100);
}
Output: 5 5 5 5 5