Difference between revisions of "JavaScript destructuring"

From Wiki @ Karl Jones dot com
Jump to: navigation, search
(Created page with "In the JavaScript programming language, the '''destructuring''' assignment syntax is an expression that makes it possible to unpack values from arrays, or properties from...")
 
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
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.
 
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 ==
 
== See also ==
Line 7: Line 16:
 
== External links ==
 
== External links ==
  
* [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment Destructuring assignment]
+
* [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment Destructuring assignment] @ developer.mozilla.org
 +
* [http://wesbos.com/destructuring-objects/ A Dead Simple intro to Destructuring JavaScript Objects] @ wesbos.com
 +
* [http://untangled.io/in-depth-es6-destructuring-with-assembled-avengers/ The Most In-Depth Yet Understandable ES6 Destructuring Tutorial] @ untangled.io
 +
* [https://css-tricks.com/new-favorite-es6-toy-destructured-objects-parameters/ Destructured Objects as Parameters] @ css-tricks.com
 +
* [http://jimrottinger.github.io/named-arguments-using-es6-destructuring/ Named and Optional Arguments in Javascript using ES6 Destructuring] by Jim Rottinger
  
 
[[Category:Computer programming]]
 
[[Category:Computer programming]]
 
[[Category:JavaScript]]
 
[[Category:JavaScript]]

Latest revision as of 12:27, 6 June 2017

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