Course contentsShow
← JavaScript
Lesson 2151 of 2,72345. Workers and ConcurrencyFree lesson

What Data Can Be Transferred?

Explore structured clone algorithm support for objects, arrays, and primitives, and what types cannot be sent to workers.

What Data Can Be Transferred?

What you'll learn: You'll understand which JavaScript values can safely cross the worker boundary and which cannot be sent via postMessage.

The Structured Clone Algorithm

When you send data to a worker using postMessage, JavaScript doesn't just pass a reference—it creates a deep copy using the structured clone algorithm. This algorithm determines what can and cannot be transferred between threads.

Think of it like packing a suitcase for a trip to another dimension: some items translate perfectly, while others simply can't make the journey.

What CAN Be Transferred

The structured clone algorithm supports:

  • Primitives: strings, numbers, booleans, null, undefined, BigInt
  • Plain objects and arrays: { name: "Alice" }, [1, 2, 3]
  • Dates: new Date()
  • RegExp: /pattern/gi
  • Maps and Sets: new Map(), new Set()
  • Typed arrays and ArrayBuffers: Uint8Array, ArrayBuffer
  • Blob and File objects

What CANNOT Be Transferred

These types will cause errors or be silently dropped:

  • Functions: Code cannot be cloned
  • DOM nodes: Workers have no access to the DOM
  • Symbols: Unique identifiers don't clone
  • Objects with prototypes (class instances): Only plain data survives
  • Error objects (fully): Stack traces may be lost

For example, if you try sending { callback: () => {} }, the callback property will be missing on the other side—functions simply cannot cross the boundary.

Why This Matters

Understanding these limits prevents subtle bugs. If you need to pass complex behavior, send data and let the worker reconstruct logic locally. Workers are for computation, not for sharing live object references.

Key Takeaway: Workers use the structured clone algorithm to copy data—primitives, plain objects, arrays, and specific built-ins work; functions, DOM nodes, symbols, and class instances do not.