Could someone explain this:
const array = [1,2,3,4];
for(let i=0; i < array.length; i++) {
setTimeout(function(){
console.log('I am at index ' + i)
}, 3000)
}
//output
I am at index 4
I am at index 4
I am at index 4
I am at index 4
const array = [1,2,3,4];
for(let i=0; i < array.length; i++) {
setTimeout(function(){
console.log('I am at index ' + i)
}, 3000)
}
//output
I am at index 0
I am at index 1
I am at index 2
I am at index 3