Spread Operator, online
Six activities your students do on their own devices. See who's finished, and their scores.
Learning
Understanding
Testing
Spread Operator in one minute
What students need to know
Spreading both arrays merges their elements together. Spreading inside a function call unpacks the array's values.
The spread operator unpacks each element of the array. [...arr] creates a new array with the same elements.
Mistakes students make
- The spread operator needs three dots, not two.
- The spread operator needs exactly three dots, not four.
- This line is actually correct - ...g copies the array.
- This line is actually correct - ...i copies the object.
PREVIOUS · MODULE 36Destructuring
YOU ARE HERE · MODULE 37Spread Operator
NEXT · MODULE 38Functions – Declaring
What students will learn in this module
Every question in Module 37
Quick questions
- Does ... expand an array's elements individually?AYesBNo
- Can the spread operator be used to copy an array?ANoBYes
- Is '..' with two dots the same as the spread operator?ANoBYes
- Can the spread operator combine two arrays into one?ANoBYes
- Can the spread operator be used with objects too?AYesBNo
Key terms
Students type the meaning of:
...
Match the pairs
[...nums]Match it to what it does{...obj}Match it to what it doesCombines two arrays into a single new arrayMatch it to what it doesPasses each array element as a separate argumentMatch it to what it doeslet b = [..a];Match it to what it doeslet d = [....c];Match it to what it doesFill in the blanks
let copy = [___nums];
Hint: Type the operator that expands the array's elements.
let arr2 = [___arr1];
Hint: Type the operator that expands the array's elements.
let objCopy = {___obj};Hint: Type the operator that expands an object's properties.
console.log(___nums);
Hint: Type the operator that expands the array's elements.
let newArr = [___oldArr, 4];
Hint: Type the operator that expands the array's elements.
Spot the error
Question 1
Alet b = [..a];Blet a = [1, 2];Cconsole.log(b);
Question 2
Alet c = [3, 4];Blet d = [....c];Cconsole.log(d);
Question 3
Alet e = {x: 1};Bconsole.log(f);Clet f = {..e};
Question 4
Alet g = [5, 6];Bconsole.log(h);Clet extra = 1;Dlet h = [...g];
Question 5
Alet i = {y: 2};Bconsole.log(j);Clet filler1 = 1;Dlet filler2 = 2;Elet j = {...i};
