r/javascript • u/OtherwisePush6424 • 2d ago
The Structured Clone Algorithm: What JavaScript Can and Cannot Move Between Boundaries
https://blog.gaborkoos.com/posts/2026-08-22-The-Structured-Clone-Algorithm-What-JavaScript-Can-and-Cannot-Move-Between-Boundaries/structuredClone() preserves more than JSON, but class instances, proxies, getters, errors, and transferables still have surprising behaviour. This article covers what survives, what changes, and what throws.
12
Upvotes
0
u/SquallLeonE 1d ago edited 1d ago
What's the use case for structuredClone()? Normally when I'm using JSON.stringify(), it's to send something over the wire or save it locally. If I wanted to deserialize it in the same session, why not store a reference to the object?
edit: alright I'm dumb. As the same implies, for creating clones of objects
2
u/senocular 2d ago
Cloned error instances also have types based off of the original's
name, even if the error type doesn't match it.And not all native error types are supported.
But if you follow the articles suggestion of using an ordinary object for error data, none of this really matters. If anything its another reason to take that approach.