LearnFrenzy
Sign in Take a free test

Spread and Rest Operators · Exercise 1 of 4

Spread and Rest Operators Spread and Rest MCQ

  • 15 questions
  • Page 1 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Fifteen multiple-choice questions on JavaScript spread and rest: telling them apart, shallow copies, merging order, null and undefined, rest parameters vs arguments, conditional spread, what object spread copies, Object.assign and limits. Pick an option to check your answer instantly.

Question 1 Easy

In function total(...prices) { return Math.max(...prices); }, what are the two ...?

A The first is rest (collects arguments), the second is spread (expands the array into arguments)
B Both are spread
C Both are rest
D The first is spread, the second is rest
Question page & discussion
Question 2 Medium

After const copy = [...matrix]; for a 2-D array, which statement is true?

A copy is a fully independent deep copy
B copy === matrix
C copy is a new outer array, but its rows are the same row arrays as in matrix
D copy contains the rows flattened into one array
Question page & discussion
Question 3 Easy

What is { ...{ size: "M", qty: 1 }, ...{ size: "L" } }?

A { size: "L", qty: 1 }
B { size: "M", qty: 1 }
C { size: "M", qty: 1, size: "L" }
D { size: "L" }
Question page & discussion
Question 4 Hard

What happens with { ...null } and [...null]?

A { ...null } gives {}; [...null] throws a TypeError
B Both give empty results
C Both throw a TypeError
D { ...null } throws; [...null] gives []
Question page & discussion
Question 5 Easy

Which function definition is valid?

A function f(...others, a) {}
B function f(a, b, ...others) {}
C function f(...a, ...b) {}
D function f(a, ...others,) {}
Question page & discussion
Question 6 Medium

Why are rest parameters preferred over the arguments object?

A They are real arrays (with map, filter …), contain only the unnamed extra arguments and work in arrow functions
B arguments is slower and deprecated in every engine
C Rest parameters copy objects deeply
D arguments cannot be read inside loops
Question page & discussion
Question 7 Easy

Why is Math.max(scores) NaN but Math.max(...scores) works?

A Math.max only works with strings
B Math.max expects separate number arguments; spread turns the array into them
C Spread sorts the array first
D Math.max(scores) works only for arrays of two items
Question page & discussion
Question 8 Easy

What is [..."ok"]?

A ["ok"]
B { 0: "o", 1: "k" }
C ["o", "k"]
D A TypeError
Question page & discussion
Question 9 Medium

What does { name, ...(isAdmin && { role: "admin" }) } produce when isAdmin is false?

A { name, role: false }
B { name, false }
C { name } – spreading false adds no properties
D A TypeError
Question page & discussion
Question 10 Hard

Which properties does { ...obj } copy?

A All properties including inherited ones
B Only string-keyed properties defined with defineProperty
C Own enumerable properties (string and symbol keys)
D Own properties, including non-enumerable ones
Question page & discussion

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links