Loading homepage
Input: deepClone({ user: { name: "Ada" }, tags: ["js", "ts"] }) Output: { user: { name: "Ada" }, tags: ["js", "ts"] } — a new root, user object, and tags array
Input: deepClone([1, [2, { active: false }], null]) Output: [1, [2, { active: false }], null] — every array and object is new
Input: deepClone(null) Output: null
Input: const input = { settings: { theme: "light" } }; const copy = deepClone(input); copy.settings.theme = "dark"; input.settings.theme; Output: "light" — changing the clone leaves the input unchanged
Input: const shared = { count: 1 }; const copy = deepClone({ a: shared, b: shared }); copy.a === copy.b; Output: false — repeated references become separate copies
deepClone(value) returns the same primitive value or a new recursively copied container. The TypeScript signature deepClone<T extends JsonValue>(value: T): T retains the input data shape and accepts readonly JSON containers. Types do not preserve object identities: every array and object occurrence is copied independently. Cloned properties are ordinary writable data properties at runtime.