
Object destructuring allows us to 'pull out' specific named 🔑s or properties from anobject literal andbind values tovariables.
This can save us some typing because we don't need to use. to access these values.
Destructuring and Renaming
As wedestructure, we can choose tobind to avariable with a different name.
The destructuringmust match the name of the 🔑 in the originalobject. It's the partafter the: that will be new 'custom'variable name.
Nested Destructuring
The destructuring process can continue as we drill down into nested objects.
You can alsorename withnested destructuring.
Destructured Function Parameters
Given somefunction that is expecting to receive anobject, we an applydestructuring to avoid using.s.
⚠️ 'References' vs 'Copies/Values'
This doesn't pertain directly todestructuring, but be aware of JS's unique behavior when it comes tomutations.
In the above code 👆🏽, wedestructured andrenamedaddress.However,me was stillmutated; both of theobjects have the 'zip plus 4.'
Withdestructuring, the same rules regarding JS Objects sharing memory references still applies.
Withprimitives, we don't need to worry.
Thestring forname wasdestructured. Because of how JS managesprimitives, a new 'copy' of this value was created (no sharedreferences forprimitives), and originalvalue inme was unchanged.
Top comments(0)
For further actions, you may consider blocking this person and/orreporting abuse



