January 2020
Intermediate to advanced
548 pages
13h 36m
English
As briefly mentioned, the left-side operand of an assignment operator (... =) can be specified as a destructuring object or array pattern, like so:
let position = { x: 123, y: 456 };let { x, y } = position;x; // => 123y; // => 456
These patterns typically look like Object or Array literals as they start and end with {} and [] respectively. They are, however, slightly different.
With the destructuring object pattern, where you want to declare the identifier or property you wish to assign to, you must place it as if it were a value in an object literal. That is, where { foo: bar } usually means assign bar to foo, in a destructuring pattern, it means assign the value of foo to the identifier, bar. It is reversed. Where ...
Read now
Unlock full access