JavaScript Spread & Rest Operator Deep Usage Quiz
Answer 35 questions exploring spread on arrays and objects, cloning behavior, combining collections, rest parameters, destructuring techniques, pitfalls, performance trade-offs, and modern practical patterns.
Question 1
What does the spread operator do when used inside an array literal?
Question 2
Which scenario benefits from spreading an array into a new one?
Question 3
What prints?
const base = [1, 2]
const extended = [...base, 3]
console.log(base)
console.log(extended)Question 4
Why might spreading a NodeList into an array be useful?
Question 5
What prints?
const user = { name: 'Ava', age: 29 }
const copy = { ...user, role: 'admin' }
console.log(copy.role)
console.log(user.role)Question 6
Which property wins when spreading multiple objects with the same key?
Question 7
Why is spreading objects preferred over Object.assign for shallow copies?
Question 8
What prints?
const base = { a: 1, b: 2 }
const extra = { b: 5, c: 6 }
const result = { ...base, ...extra }
console.log(result)Question 9
Why is spread considered a shallow copy?
Question 10
Which approach creates an independent nested object clone?
Question 11
What prints?
const original = { stats: { score: 90 } }
const clone = { ...original }
clone.stats.score = 50
console.log(original.stats.score)Question 12
Why can spreading arrays help avoid mutation bugs?
Question 13
What advantage does spreading multiple arrays into one provide?
Question 14
What prints?
const left = ['a', 'b']
const right = ['c']
const combined = [...left, 'mid', ...right]
console.log(combined)Question 15
How can you combine arrays while adding unique IDs?
Question 16
Why is spread helpful when merging configuration objects?
Question 17
What does the rest parameter syntax do in a function signature?
Question 18
What prints?
function sum(label, ...values) {
return `${label}:${values.reduce((a, b) => a + b, 0)}`
}
console.log(sum('total', 2, 3, 4))Question 19
Why is rest preferred over the arguments object?
Question 20
How many rest parameters may a function have?
Question 21
What prints?
const collect = (...args) => args.join(',')
console.log(collect('a', 'b', 'c'))Question 22
Why is rest useful in wrapper functions?
Question 23
How can rest help with default argument patterns?
Question 24
What prints?
const [first, ...others] = [10, 20, 30]
console.log(first)
console.log(others)Question 25
Why can object rest in destructuring be handy?
Question 26
What restriction applies to rest in array destructuring?
Question 27
What prints?
const user = { id: 1, name: 'Lee', role: 'dev' }
const { role, ...identity } = user
console.log(role)
console.log(identity)Question 28
Why might spreading undefined in an array literal throw an error?
const arr = [...undefined]Question 29
What is a common mistake when spreading objects with methods?
Question 30
What prints?
const config = { get value() { console.log('computed'); return 5 } }
const copy = { ...config }
console.log(copy.value)Question 31
Why can spreading large arrays hurt performance?
Question 32
When merging arrays frequently, what alternative might be faster?
Question 33
What prints?
function combine(...arrays) {
return [].concat(...arrays)
}
console.log(combine([1], [2, 3]))Question 34
What performance cost arises when spreading objects with many properties?
Question 35
Why are spread and rest central to modern JS patterns?
