Course contentsShow
← JavaScript
Lesson 2004 of 2,72341. Modern JavaScript Features (ES2020+)Free lesson

What structuredClone Can and Cannot Clone

Supported types including nested objects, arrays, Maps, Sets, Dates, and what fails (functions, DOM nodes, symbols).

What structuredClone Can and Cannot Clone

You'll learn: Which JavaScript values structuredClone can successfully copy and which ones it cannot handle.

Understanding the Structured Clone Algorithm

When you call structuredClone(), it uses the browser's built-in structured clone algorithm—the same mechanism used when posting messages between workers or storing data in IndexedDB. This algorithm knows how to handle many types of JavaScript values, but not everything.

Think of it like a sophisticated photocopier that understands complex documents (nested folders, tables, spreadsheets) but chokes on certain special materials (living plants, mirrors, certain chemicals).

What structuredClone CAN Clone

The good news: most common data structures work perfectly:

  • Primitive values: strings, numbers, booleans, null, undefined, BigInt
  • Objects and arrays: including deeply nested ones
  • Built-in types: Date, RegExp, Map, Set, ArrayBuffer, TypedArray, DataView, Blob, File
  • Error objects: Error, TypeError, etc.
const original = {
  date: new Date(),
  map: new Map([['key', 'value']]),
  nested: { deep: { data: [1, 2, 3] } }
};

const copy = structuredClone(original);
// ✅ Works perfectly

What structuredClone CANNOT Clone

Here's where it fails:

  • Functions: any kind of function or method
  • DOM nodes: elements, documents, windows
  • Symbols: both regular and well-known symbols
  • Prototypes: only plain object structure is cloned
  • Non-enumerable properties
  • Property descriptors: getters, setters, configurability
const obj = {
  fn: () => {},          // ❌ Will throw
  sym: Symbol('test'),   // ❌ Will throw
  element: document.body // ❌ Will throw (in browser)
};

// structuredClone(obj); // TypeError!

Key Takeaway: structuredClone handles most data structures (objects, arrays, Maps, Sets, Dates) but fails on functions, DOM nodes, and symbols—it's designed for data, not behavior.