Here is a JavaScript arrow function I found in a React book:
const createArray = (length) => [...Array(length)];
Why not simply return a new array?
const createArray = (length) => Array(length);
If I log the result of createArray(7) with either of the definitions, I get the same result:
(7) [undefined, undefined, undefined, undefined, undefined, undefined, undefined]
What does the first definition achieve as compared to the second one?
Array(5)=>[empty x 5]vs.[...Array(5)]=>[undefined, undefined, undefined, undefined, undefined]. The difference is initialisation.