The JSON stringify-parse dance was everyone's deep copy for a decade, and it quietly destroyed dates, maps, and anything circular. structuredClone is the platform answer, spectacularly better where it counts.
const copy = structuredClone(cart);- It copies the types JSON cannot: Date, Map, Set, typed arrays, and cyclic structures come back intact instead of stringified or thrown.
- It still refuses functions and DOM nodes, which keeps view-layer state and event handlers out of your data clones by design.
- Class instances clone as plain objects; methods and private fields do not survive, so rebuild real behavior from a factory when you need it back.
Where it earns its place
State snapshots for undo, optimistic patches in a cart, form drafts for an autosave queue: any place the copy must be independent of the live object or live in storage. A JSON round trip in those spots is a bug waiting for a Tuesday.
One caveat worth saying out loud: the clone is not a security boundary, it copies data; escaping a page is a different problem with different tools. gacor to finally have a first-class word for a deep copy: hire the right tool, delete the stringify hack.
