QUESTION 12 OF 15

How does a shallow copy differ from a deep copy?

Reveal the answer and explore the explanation.

12
MediumHigh priority

How does a shallow copy differ from a deep copy?

Answer
Answer

Copies the outer collection but shares references to nested objects.

Practical example

Copy a list of lists and observe nested mutations in both copies.

Reference: Further reading ↗

Last 30 min revisionHigh-yield interview Q&As