cf.completefrontend

Predict the outputHard

How do array methods treat the hole in [1, , 3]?

What does this log?
const arr = [1, , 3];
console.log(arr.length, 1 in arr, arr[1]);
console.log(arr.map((n) => n * 2));
 
let calls = 0;
arr.forEach(() => calls++);
console.log(calls);
 
console.log(Object.keys(arr));
console.log([...arr]);
console.log(arr.indexOf(undefined), arr.includes(undefined));

The answer

Work out every line it logs, in order. Then check.

Checking your sign-in…