Skip to main content

Reference identity and shallow vs deep copies

Why does changing a nested property in a spread copy sometimes modify the original? How would you update it immutably?

Official Reference

Model Answer & Explanation

Assignment copies the object reference value. An object spread copies own enumerable properties into a new outer object, but nested object values still reference the same objects. For an immutable update, copy each object along the changed path. structuredClone can deeply copy many data types, but it cannot clone functions.

Follow-up Interview Question · When is sharing the untouched branches desirable?

Module Context & References

JavaScript · Language theory Explain scope, closures, this, prototypes, equality and references
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.