JavaScript destructuring

From Wiki @ Karl Jones dot com
Revision as of 12:27, 6 June 2017 by Karl Jones (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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