DEV Community

Discussion on: You don't know spread operator !

Collapse
ca0v profile image
Corey Alix

Why is it dangerous?

Collapse
parsyvalentin profile image
Valentin PARSY Author

The Number primitive wrapper object is used EVERYWHERE. If you change anything that "low-level" in your code, it will change it everywhere in your code/app, potentially changing the behavior of (in this example) every Number you use.

As a solution you could have your own IterableNumber, that is a Number to which you set the Symbol.iterator property. (not sure it is a good solution though)

Collapse
loclv profile image
LuuVinhLoc

I think there are a case to be made teammate (include me) confused.

a = 8
[...a]
// output 🚀: [1, 2, 3]

// now set it's value again
a = 's'
[...a]
// output 🚀: ['s']
Enter fullscreen mode Exit fullscreen mode