JavaScript Quirks

Deep Clone

mediumjs-quirksrecursionobjects
0:00

Problem

Implement `deepClone(obj)` that returns a deep copy of the given object. The result should be structurally equal to the input but should NOT share nested references. Assume inputs are plain JSON-safe values (primitives, arrays, plain objects).

Your solution
Test results
Click Run tests to check your solution against the test cases.

About this challenge

Deep Clone is a medium javascript quirks coding challenge. It explores a surprising corner of JavaScript's behavior — the kind of gotcha that causes real bugs. Write your solution in the editor above, run it against the test cases, and get instant feedback — free, in your browser, no sign-up.

Show a hint & approach (spoiler)

Hint: Recurse through arrays and plain objects. For JSON-safe inputs, `JSON.parse(JSON.stringify(obj))` works as a quick solution.

Keep practicing

Browse all coding challenges, or build intuition for the underlying concepts with the algorithm visualizers and the developer cheatsheets.