The destructuring assignment
syntax is a JavaScript expression that makes it possible to extract data from arrays or objects into variables.
How to extract the values is specified via patterns
:
const user = { first: 'John', last: 'Doe', age: 35 };
const numbers = [1, 2, 3, 4, 5];
// Object destructuring
const { first, age } = user; // John, 35;
// Array destructuring
const [a, b, c] = numbers; // 1, 2, 3
- For variable declarations and assignments.
- Parameter definitions.
- In a
for-of
loop.
All destructuring tips and tricks are covered using (failing) unit tests. It's up to you to make the tests pass. You can use the test/workshop.js file.
Clone the project and:
- Run
npm install
. - Followed by
npm test
ornpm start
to watch. - Enjoy!