I've noticed that if I do:
Array(n).map(() => console.log('test'))
I get nothing printed.
However if I do:
Array(n).fill().map(() => console.log('test'))
I get test printed out n times.
Why is this the case? If I do Array(n).length I get back n.
I notice in the REPL that Array(5) returns:
[ , , , , ]
Whereas Array(5).fill() returns:
[ undefined, undefined, undefined, undefined, undefined ]
In both cases, typeof any element in the array === undefined.
So, what's going on?