Assigning, Mutating, and Freezing a JS object
I've been using Object.assign
to merge two objects in javascript. That typically looks like this:
The key/values in the second argument override the key/values in the first object to produce a new object with those the combined keys and values.
Does it actually produce a new object? or does it just mutate the first argument:
Ahh... it mutates. If you prefer something not to mutate you can freeze it:
Ok, so now Object.assign
can't mutate the first argument, because that argument is frozen. But be careful, freeze
mutates too.