es6-destructuring Flashcards
What is destructuring, conceptually?
Assigning properties of an object or indexes of an array to variables in one line
or
Allows the creation of variables from properties of objects or indexes of arrays
What is the syntax for Object destructuring?
let { property1: variable1, property2: variable2 } = object;
What is the syntax for Array destructuring?
let [index1, index2, index3] = nameOfArray;
How can you tell the difference between destructuring and creating Object/Array literals?
In de-structuring objects or arrays, the name of the object or array is on the right side of the assignment operator; and to the left of the assignment operator for an object de-structuring, the property or index name is on the left side of the colon and the variable name is on the right side of the colon.
For array de-structuring, the indexes are listed within brackets ( [ ] ).