1. structuredClone
structuredClone recursively clones nested objects and even handles cyclic references.
const deep = structuredClone(obj)Typorithm · easy
Step 1 of 8 · intro card
Copy & Equality
structuredClone(obj) is the modern way to deep-clone: it recurses through nested objects and even handles cycles. The older JSON.parse(JSON.stringify(obj)) trick also deep-copies but drops functions and undefined and turns Dates into strings.
structuredClone(obj) produces a fully independent deep copy — every nested object and array is cloned, and it can handle cyclic references that would crash JSON.
The classic JSON.parse(JSON.stringify(obj)) trick deep-copies anything JSON can represent, but it has real limits: functions and undefined values are dropped, and Date objects come back as strings.
Prefer structuredClone for correctness. Reach for the JSON trick only for plain, JSON-safe data, and never when the object contains functions, Dates, Maps, or cycles.
structuredClone deep-copies nested objects and handles cycles.
JSON.parse(JSON.stringify(obj)) deep-copies only JSON-safe data.
The JSON trick drops functions/undefined and stringifies Dates.
const obj = { when: new Date(), tags: ["a", "b"] }
const deep = structuredClone(obj)
// older trick — has limits
const viaJson = JSON.parse(JSON.stringify(obj))
// functions dropped, undefined dropped, Date becomes a stringConnect each part of the code to the concept before you type.
structuredClone recursively clones nested objects and even handles cyclic references.
const deep = structuredClone(obj)Serializing to JSON and back deep-copies, but only data that survives JSON.
const viaJson = JSON.parse(JSON.stringify(obj))The JSON trick drops functions and undefined, and turns Dates into strings.
// functions dropped, undefined dropped, Date becomes a stringstructuredClone preserves the Date object; JSON would flatten it to a string.
new Date()Read the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.