Destructuring pulls fields from objects/arrays into variables. Spread ... copies or merges shallowly.
Examples
const { name, id } = user;const [first, ...rest] = items;fn(...args)— expand array as arguments
Defaults
const { role = 'guest' } = user; — defaults apply when property undefined.
Important interview questions and answers
- Q: rest in destructuring?
A: Collects remaining properties into new object. - Q: Shallow copy?
A: Spread clones top level only—nested objects still shared.
Self-check
- What does ...rest collect in arrays?
- How merge two objects?
Tip: Re-run the playground code for destructuring-spread and tweak one line before the MCQs.
Interview prep
- Shallow spread?
Top-level keys only—nested objects shared.