What is the difference between "Array(n)" and "[...Array(n)]"?

Viewed 146

What is the difference between the two?

// Chrome console

Array(2);                   // [undefined × 2]
Array(2).map(() => 1);      // [undefined × 2]

[...Array(2)];              // [undefined, undefined]
[...Array(2)].map(() => 1); // [1, 1]

Based on What are Array empty slots?, it seems to be related to memory allocation, but why does the spread operator suddenly cause memory to be allocated in the latter case?

1 Answers
Related