Es6 distructing part 3
Object Destructuring in ES6
Similar to Array destructuring, Object destructuring unpacks properties into distinct variables.
For example:
We can assign without declaration, but there are some syntax requirements for that:
The () with a semicolon (;) at the end are mandatory when destructuring without a declaration. However, you can also do it as follows where the () are not required:
You can also assign the object to new variable names.
For example:
Finally you can assign default values to variables, in case the value unpacked from the object is undefined.
For example:
Tap Try it Yourself to play around with the code.
Comments
Post a Comment