Destructuring, online

Six activities your students do on their own devices. See who's finished, and their scores.

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.

Discover other journeys with this module

What students will learn in this module

Every question in Module 36

Quick questions

  1. Does array destructuring use square brackets?AYesBNo
  2. Does object destructuring use curly braces?AYesBNo
  3. Is () valid for destructuring an array or object?AYesBNo
  4. Do object destructuring variable names need to match the keys?AYesBNo
  5. 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 does
let {name, age} = person;Match it to what it does
Unpacks values from an array by their positionMatch it to what it does
Unpacks properties from an object into matching variablesMatch it to what it does
let (a, b) = [1, 2];Match it to what it does
let (name, age) = person;Match it to what it does

Fill in the blanks

  1. let _a, b] = [1, 2];

    Hint: Type the symbol that opens array destructuring.

  2. let [i, j] = _3, 4];

    Hint: Type the symbol that opens the array being destructured.

  3. let _name, age} = person;

    Hint: Type the symbol that opens object destructuring.

  4. let {name, age_ = person;

    Hint: Type the symbol that closes object destructuring.

  5. 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)