DEV Community

Discussion on: If you Wannabe (assigned) in my JS Object: Conditionally adding properties to JS Objects

Collapse
 
the_riz profile image
Rich Winter

Does using the spread {..._} operator or Object.assign() duplicate the object in memory instead of simply extending the existing one?

Collapse
 
silvestricodes profile image
Jonathan Silvestri

Good question! Object.assign does not duplicate the target object in memory - it adds on to the existing object, and in the case of clashing keys, the keys and their values from the added object will overwrite the existing one.

With that being the case, the same answer applies to the spread operator.