Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The "..." is called a spread operator in javascript.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

(In python there is the "*" operator which should be equivalent: [1, 2, *arr].

Array(clicks) instantiate an array of length 'clicks', with its elements undefined.

Then "[...Array(clicks)]" takes the above array instance and spreads it as content in another array.

Seems redundant and they could've just used Array(clicks).



> Array(clicks) instantiate an array of length 'clicks', with its elements undefined.

Not undefined elements but no elements, or "empty" elements.

> they could've just used Array(clicks).

No, because the following forEach call does nothing for such an array. You need to fill the array first with Array(clicks).fill() or shorter, [...Array(clicks)]




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: