Spread and Rest Operators — JS Technical Interview Questions & Answers
The ... syntax for expanding and collecting values.
Spread and Rest Operators
- Spread and Rest Operators (js) is a JS topic. In plain words you use it for { name, marks } in a student record. Don’t start with a slogan — start with that picture.
- Smallest example: const { name } = student. Type it, run it, and say what you see. If you can do that from memory, you know Spread and Rest Operators (js).
- From the example next to this theory: The ... syntax for expanding and collecting values..
- Trap: copying nested objects by accident (shallow copy). Fix that before you talk about advanced JS.
- Viva: what is Spread and Rest Operators (js)? Then show const { name } = student. Then name the trap.
Technical Interview Tip: What is Spread and Rest Operators (js)? Show this: const { name } = student. Trap: copying nested objects by accident (shallow copy).
Code Examples for Spread and Rest Operators
Spread and Rest Operators — working example
const add = (a, b) => a + b;
const name = "Ada";
console.log(`Hi, ${name}!`);
const user = { name: "Lin", city: "Pune", skills: ["CSS"] };
const { city, ...rest } = user;
const skills = [...user.skills, "JS"];
console.log(add(2, 3), city, rest, skills);
console.log(user.profile?.bio ?? "n/a");Spread and Rest Operators — modern JS: arrows, template strings, destructuring, spread/rest, ?. and ?? for safe defaults.
How to Explain Spread and Rest Operators to an Interviewer
What is Spread and Rest Operators (js)?
Used for { name, marks } a student record Not just the heading
Give one small example of Spread and Rest Operators (js).
const { name } = student The ... syntax for expanding and collecting values.
What mistake do beginners make with Spread and Rest Operators (js)?
copying nested objects by accident (shallow copy) Show the fix
Where do you use Spread and Rest Operators (js)?
a student record { name, marks }