Skip to main content
JavaScript Interview Questions Predict Output P0 Medium

Nested mutation after object spread

What values survive the mutation and subsequent replacement?

Official Reference

Code Snippet

const original = { prefs: { volume: 3 } };
const copy = { ...original };
copy.prefs.volume++;
copy.prefs = { ...copy.prefs, volume: 9 };
console.log(original.prefs.volume, copy.prefs.volume);
console.log(original.prefs === copy.prefs);

Expected Output & Explanation

4 9
false

The first mutation uses the shared nested object. The later spread assigns a different nested object to copy only.

Module Context & References

JavaScript · Language output drills Trace closures, receivers, prototypes, coercion and array edge cases
Personal Notes · Markdown

Technologies & Interview Topics Covered

Switch between short-term interview tracks and long-term 80/20 engineering depth to practice JavaScript internals, React rendering and hooks, timed frontend machine coding UI challenges, MeetaPro FG300, Blind 75 & NeetCode 150 DSA patterns, Python & FastAPI APIs, PostgreSQL query optimization & MVCC, Redis caching, Applied AI RAG pipelines & evaluations, and distributed system design.