JavaScript
/Advanced
Implement: Deep Clone Object
Definition
Write a function that recursively copies an object so that no nested objects share a memory reference with the original. Cannot use `JSON.parse` or `structuredClone`.
Explain Like I'm New
The interviewer wants to see if you can handle recursion with complex data types, specifically filtering out Arrays vs Objects vs Primitives, and handling edge cases like `null`.
Real World Example
Cloning `{ a: 1, b: { c: 2 } }`.
Common Use Cases
- •Interview screening
- •Understanding JS data types
Interactive Example
Loading...
Console output will appear here...
Interview Questions
basic
- Why does `typeof null` complicate this question?
intermediate
- Write a recursive deep clone function.
advanced
- How would you handle circular references in a deep clone function?