for (var i = 0; i < 3; i++) {
const log = () => {
console.log(i)
}
setTimeout(log, 100)
}
The output it gives is 3 3 3
which I have no idea why. It was asked in an interview and I want to understand the output
for (var i = 0; i < 3; i++) {
const log = () => {
console.log(i)
}
setTimeout(log, 100)
}
The output it gives is 3 3 3
which I have no idea why. It was asked in an interview and I want to understand the output