While JavaScript is famous for its single-threaded Event Loop, modern browsers provide true hardware-level multithreading via the Web Workers API. Web Workers run scripts in background threads, enabling CPU-intensive operations (image processing, cryptographic hashing, 3D physics, big-data filtering) without blocking the main UI thread.
document.querySelector, window)parent objectfetch() and XMLHttpRequestIndexedDBWebSocketscrypto.subtlesetTimeout, setIntervalworker.js)app.js)By default, data passed via postMessage() is cloned using the Structured Clone Algorithm (deep copy), which can be slow for 500MB video buffers or typed arrays.
Transferable Objects transfer memory ownership instantly with zero copy ($O(1)$ transfer time). The sender relinquishes ownership:
When building components with Vite or Webpack, you can create Workers dynamically from string literals:
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Async Generators & For-Await-Of | Custom Error Hierarchies & Prototypes |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.
Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.