Intermediate
JavaScript
Q50 / 100
What is the difference between shallow and deep copy in JavaScript?
Correct! Well done.
Incorrect.
The correct answer is B) Shallow copy copies only the top-level properties by reference; deep copy recursively copies all nested objects
B
Correct Answer
Shallow copy copies only the top-level properties by reference; deep copy recursively copies all nested objects
Explanation
const shallow = { ...obj } shares nested object references. Deep copy: structuredClone(obj) (modern) or JSON.parse(JSON.stringify(obj)) (limited).
Progress
50/100