Q23: What is the difference between a Shallow Copy and a Deep Copy?
A shallow copy (Object.assign(), {...obj}) copies top-level properties, but nested objects/arrays retain memory references. A deep copy (structuredClone(), JSON.parse(JSON.stringify())) recursively duplicates all nested structures, creating completely independent object graphs.
Key Takeaways
Shallow copy leaves nested objects linked by reference.
Deep copy duplicates all nested layers independently.
Knowledge Check
Which modern native JavaScript global function performs deep copying safely?