← All Exercises
Deep Clone Object
intermediatejavascript
Background
Deep cloning prevents unintended mutations when working with nested data structures in state management.
Problem
Write a function that creates a deep copy of an object or array, ensuring no references are shared between the original and the clone.
Input
A plain object, array, or primitive value that may contain nested structures.
Output
A deep copy with no shared references to the original.
Sample tests
Sample 1
Input: {a: {b: {c: 1}}}Expected: {a: {b: {c: 1}}} (no shared refs)Your solution
Learning objective
Understand shallow vs deep copying and recursive object traversal.