That's because undefined
is a value, while when you create an array for example like this:
var array = [];
array.length = 10;
console.log(array);
>(10) [empty × 10] // in google chrome
10 empty slots are created.
The empty slot is different from the undefined value, and the most important difference is that the empty slot is not Enumerable.
var mappedArray = array.map(x => 1);
console.log(mappedArray);
>(10) [empty × 10] // in google chrome
Since map
function enumerates the values in the orriginal array and returns the array of the same length, it has no effect on the array of 10 empty slots.
Note that empty slots are named differently in different browsers.