Although the gist of the above is correct, the right hand side of the following code creates a copy of the firstObject before extracting age, and creating secondObject, allocating more memory unnecessarily.
const{age,...secondObject}={...firstObject};
The following achieves the same outcome, but skips the extra allocation.
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 💪🏾
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 💪🏾
Although the gist of the above is correct, the right hand side of the following code creates a copy of the
firstObject
before extractingage
, and creatingsecondObject
, allocating more memory unnecessarily.The following achieves the same outcome, but skips the extra allocation.
Thank you for the explanation, you are absolutely correct about this. That was is more efficient 👍
You might wanna update your original post for people who don't read the comments. 😉
Good catch, thanks!
Lost track of it, updated :)