Started coding at the age of 13, now a professional software engineer and Scrum Master, creating and maintaining enterprise solutions. Eat - Sleep - Code - Lift - Repeat 💪🏾
I am using it in the React environment quite often and I'm curious if you have a clue about how the performance is compared to the equal methods like copying an array with spreading vs copying it via slice()?
Software dev at Netflix | DC techie | Conference speaker | egghead Instructor | TC39 Educators Committee | Girls Who Code Facilitator | Board game geek | @laurieontech on twitter
It depends on the JS engine running, i.e. chrome vs safari. My understanding is that slice used to be more performant but that gap has been cut significantly and on many browsers, the spread operator is the same, or possibly better performance wise.
And since slice() only works for arrays, the spread operator is a more powerful piece of syntax.
Started coding at the age of 13, now a professional software engineer and Scrum Master, creating and maintaining enterprise solutions. Eat - Sleep - Code - Lift - Repeat 💪🏾
I am using it in the React environment quite often and I'm curious if you have a clue about how the performance is compared to the equal methods like copying an array with spreading vs copying it via slice()?
It depends on the JS engine running, i.e. chrome vs safari. My understanding is that slice used to be more performant but that gap has been cut significantly and on many browsers, the spread operator is the same, or possibly better performance wise.
And since slice() only works for arrays, the spread operator is a more powerful piece of syntax.
Thanks for the answer, wasn't aware of it but a quick research confirmed it :)