Array(totalStars)creates an array with the totalStarsnumber of empty slots. Using the spread operator leads to the forced filling of empty slots in undefined, effectively filling the SOMETHING array for display (even if it is undefined).
Just creating an instance of the array with the help Array()does not put spaces in it, it just allocates space for them.
source
share