Object Shallow Copy
Multiple Choice Medium
Question
What does Object.assign({}, obj) create?
Hint
Object.assign does a shallow copy.
Explanation
Object.assign({}, obj) creates a shallow copy — top-level properties are copied, but nested objects are still shared by reference. For deep copies, use structuredClone() (modern browsers) or JSON.parse(JSON.stringify(obj)) (with limitations). The spread operator {...obj} also creates a shallow copy.
Related Resources
Related Lessons
- Objects
Learn JS objects.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.