Spread Operator

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Spread Operator

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Does ... expand an array's elements individually?
A Yes
B No
2. Can the spread operator be used to copy an array?
A No
B Yes
3. Is '..' with two dots the same as the spread operator?
A No
B Yes
4. Can the spread operator combine two arrays into one?
A No
B Yes
5. Can the spread operator be used with objects too?
A Yes
B No

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1[...nums] ACreates a new object with a copy of obj's properties
2{...obj} BWrong - the spread operator needs exactly three dots
3Combines two arrays into a single new array C[...arr1, ...arr2]
4Passes each array element as a separate argument DCreates a new array with a copy of nums' elements
5let b = [..a]; EWrong - the spread operator needs three dots, not two
6let d = [....c]; Fconsole.log(...nums)

Definitions

...

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
let copy = [___nums];
2.
let arr2 = [___arr1];
3.
let objCopy = {___obj};
4.
console.log(___nums);
5.
let newArr = [___oldArr, 4];

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A let b = [..a];
B let a = [1, 2];
C console.log(b);
Question 2
A let c = [3, 4];
B let d = [....c];
C console.log(d);
Question 3
A let e = {x: 1};
B console.log(f);
C let f = {..e};
Question 4
A let g = [5, 6];
B console.log(h);
C let extra = 1;
D let h = [...g];
Question 5
A let i = {y: 2};
B console.log(j);
C let filler1 = 1;
D let filler2 = 2;
E let j = {...i};

Answer Key

Spread Operator
Section A: Quick Questions
Q1
A — Yes
Q2
B — Yes
Q3
A — No
Q4
B — Yes
Q5
A — Yes
Section B: Match the Pairs
Q1
[...nums] → Creates a new array with a copy of nums' elements
Q2
{...obj} → Creates a new object with a copy of obj's properties
Q3
Combines two arrays into a single new array → [...arr1, ...arr2]
Q4
Passes each array element as a separate argument → console.log(...nums)
Q5
let b = [..a]; → Wrong - the spread operator needs three dots, not two
Q6
let d = [....c]; → Wrong - the spread operator needs exactly three dots
Section C: Definitions
Q1
... — Expands an array or object's elements individually, often used to copy or combine them.
Section D: Fill in the Blanks
Q1
let copy = [...nums];
Q2
let arr2 = [...arr1];
Q3
let objCopy = {...obj};
Q4
console.log(...nums);
Q5
let newArr = [...oldArr, 4];
Section E: Spot the Error
Q1
A — The spread operator needs three dots, not two.
Q2
B — The spread operator needs exactly three dots, not four.
Q3
C — The spread operator needs three dots, not two.
Q4
D — This line is actually correct - ...g copies the array.
Q5
E — This line is actually correct - ...i copies the object.