What does the following output?
# what will the following code output?
const arr = [5, 9, 4, 12];
for (var i = 0; i < arr.length; i++) {
setTimeout(function() {
console.log('Index: ' + i + ', element: ' + arr[i]);
}, 3000);
}
One possible answer is Index: 4, element: banana
. Why?
arr.splice(4, 0, 'banana')
Or the answer might be popcorn
. Why?
const log = console.log
console.log = function() { log('popcorn') }