cf.completefrontend

Predict the outputMedium

What does this log about new Array(n), Array.of, and writing to length?

What does this log?
const a = new Array(3);
console.log(a.length, Object.keys(a));
console.log(Array.of(3), new Array("3"));
 
const b = [1, 2, 3, 4, 5];
const alias = b;
b.length = 2;
console.log(alias);
b[4] = "e";
console.log(b.length, Object.keys(b));
 
console.log(new Array(-1));

The answer

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

Checking your sign-in…