LESSON 11 / 16·2 min readIntermediate

Is spread a deep copy?

Try code in the playground
01 Understand02 Recall03 Prepare

Understand the concept

Spread syntax creates a new outer object or array by copying its enumerable contents. It is a shallow copy, so nested objects are still shared references. This matters when updating React state or copying request data that another part of the application may modify.

Important ideas

  • No. { ...user } copies only the first level.

  • Nested objects still share references.

  • Copy each changed level, or use structuredClone for supported data types.

  • Changing a top-level field in the copy does not change that field in the original.

  • structuredClone supports many nested data types, but not functions and not every custom object behavior.

Work through the example

JavaScript
const original = { address: { city: 'Surat' } };
const copy = { ...original };
copy.address.city = 'Ahmedabad';
console.log(original.address.city); // Ahmedabad
  • Both outer objects still point to the same nested address object.
PAUSE & RECALL

Can you explain it without the notes?

Is spread a deep copy?

Use your own words. Explain an example and one limitation before checking the explanation.

Check your explanation

Spread syntax creates a new outer object or array by copying its enumerable contents. It is a shallow copy, so nested objects are still shared references. This matters when updating React state or copying request data that another part of the application may modify.

CONNECT IT TO YOUR INTERVIEW

Turn this concept into a clear answer.

  • Show the nested reference that remains shared; do not describe spread as complete immutability.
Practice this concept
YOUR NEXT STEP

Keep connecting the ideas.

Next lesson: Debounce vs throttle: what is the difference?

Adapted from 01_JAVASCRIPT_TYPESCRIPT.md · “Is spread a deep copy?”. Examples are study fragments; framework behavior can depend on your version.