The "A. Using Spread" example fails to demonstrate the error, since it says return [...array1, array2] instead of return [...array1, ...array2] (it doesn't actually spread the string)
Instead it demonstrates the happy path of "immutably pushing" the string.
return [...array1, array2]
return [...array1, ...array2]
I firmly believe concat is dangerous and should only be used with arrays, not loose elements. Because your loose element will end up being an array someday, and you will SUFFER.
And on the other hand, it doesn't work on arraylikes:
.concat([document.querySelector('body')],document.querySelectorAll('*')) // nope
;[document.querySelector('body'), ...document.querySelectorAll('*')] // yep
Oops, that’s a typo 😬 let me fix that 😰
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.