es6-destruturing Flashcards
What is destructuring, conceptually?
Assigns properties of an object (or values of an array) to individual variables
What is the syntax for Object destructuring?
Let { property1: variable1, property2: variable2 } = objectName;
let/const, opening curly brace, property name. Colon, variable name, comma, repeat for any other properties, closing curly brace, equal sign, object’s name, semicolon
What is the syntax for Array destructuring?
Let [x, y, z] = array;
let/const, opening brackets, name of variable separated by commas, closing bracket, equal sign, name of array, semicolon
How can you tell the difference between destructuring and creating Object/Array literals?
Destructuring: the object/array name goes on the right of the assignment operator, braces/brackets are on the left side of the assignment operator
Creating: the variable name goes on the left of the assignment operator, braces/brackets are on the right side of the assignment operator