Destructuring, online
Six activities your students do on their own devices. See who's finished, and their scores.
Learning
Understanding
Testing
Destructuring in one minute
What students need to know
x becomes 5 and y becomes 6, based on their order. city and zip must match the property names in place.
let [a, b] = array unpacks values using square brackets. Destructuring never uses round brackets - only [] or {}.
Mistakes students make
- Array destructuring uses square brackets [], not round brackets.
- The array being destructured needs [], not ().
- Object destructuring uses curly braces {}, not round brackets.
- Object destructuring must open and close with {} to match.
PREVIOUS · MODULE 35Nested Arrays and Objects
YOU ARE HERE · MODULE 36Destructuring
NEXT · MODULE 37Spread Operator
What students will learn in this module
Every question in Module 36
Quick questions
- Does array destructuring use square brackets?AYesBNo
- Does object destructuring use curly braces?AYesBNo
- Is () valid for destructuring an array or object?AYesBNo
- Do object destructuring variable names need to match the keys?AYesBNo
- Does array destructuring assign values by their position?ANoBYes
Key terms
Students type the meaning of:
destructuring
Match the pairs
let [a, b] = [1, 2];Match it to what it doeslet {name, age} = person;Match it to what it doesUnpacks values from an array by their positionMatch it to what it doesUnpacks properties from an object into matching variablesMatch it to what it doeslet (a, b) = [1, 2];Match it to what it doeslet (name, age) = person;Match it to what it doesFill in the blanks
let _a, b] = [1, 2];
Hint: Type the symbol that opens array destructuring.
let [i, j] = _3, 4];
Hint: Type the symbol that opens the array being destructured.
let _name, age} = person;
Hint: Type the symbol that opens object destructuring.
let {name, age_ = person;Hint: Type the symbol that closes object destructuring.
let [x, y] _ [5, 6];
Hint: Type the symbol used to assign the array's values.
Spot the error
Question 1
Alet (a, b) = [1, 2];Bconsole.log(a);Cconsole.log(b);
Question 2
Aconsole.log(c);Blet [c, d] = (3, 4);Cconsole.log(d);
Question 3
Aconsole.log(name);Bconsole.log(age);Clet (name, age) = person;
Question 4
Aconsole.log(city);Blet {city, zip] = place;Cconsole.log(zip);
Question 5
Alet [e, f] = [7, 8];Bconsole.log(e);Cconsole.log(f)
