JavaScript destructuring
From Wiki @ Karl Jones dot com
In the JavaScript programming language, the destructuring assignment syntax is an expression that makes it possible to unpack values from arrays, or properties from objects, into distinct variables.
Destructured objects as parameters
Destructuring can help us easily extract and manipulate data from arrays or objects into distinct variables and make our parameters more meaningful. This helps us communicate our intentions to readers in the future and helps with maintenance.
- You no longer have to remember the specific ordering
- We can easily have optional parameters
- We can have defaults, which is also nice because it’s self-documenting
- We can have fallbacks for failure conditions, or decide not to if we want to show an error
See also
External links
- Destructuring assignment @ developer.mozilla.org
- A Dead Simple intro to Destructuring JavaScript Objects @ wesbos.com
- The Most In-Depth Yet Understandable ES6 Destructuring Tutorial @ untangled.io
- Destructured Objects as Parameters @ css-tricks.com
- Named and Optional Arguments in Javascript using ES6 Destructuring by Jim Rottinger