Shallow Copy

Noun · Development

Definitions

  1. A copy of an object that duplicates the top-level structure but shares references to nested objects with the original, meaning mutations to nested children are visible in both the copy and the source — as opposed to a deep copy, which recursively clones everything.

    In plain English: Copying an object where the outer container is new but the inner items are still shared, so changes to inner items affect both copies.

    Example: "Spreading the array created a shallow copy, so pushing into the nested sub-array mutated the original too — we needed structuredClone."

Related Terms