Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Web Workers – Background Threadin | JavaScript Course lesson | BraveProgrammer
  1. Courses
  2. /
  3. JavaScript Course

Lesson 26 of 55

·javascript

Web Workers – Background Threading

9 mins

Course progress47%

What you'll learn

Keep these ideas in mind as you work through the lesson.

4 points
  • `Web Worker` objects have their own global scope (`self`).
  • Communicate via **structured cloning** – objects are copied, not shared.
  • Use **`Transferable`** objects (e.g., `ArrayBuffer`) for zero‑copy transfers.
  • Terminate workers with `worker.terminate()` when done.

Web Workers run in a separate thread with no direct DOM access.

// worker.js
self.addEventListener('message', e => {
  const result = heavyCalc(e.data);
  self.postMessage(result);
});

Main thread:

const worker = new Worker('worker.js');
worker.postMessage(42);
worker.onmessage = e => console.log('Result:', e.data);
Make it stickPractice what you've learned1 quiz · 7 practical tests · Optional activities from JavaScript CourseBrowse activities
Previous lessonJavaScript Performance – Profiling & OptimisationContinue to lesson 27Service Workers – Offline Caching & PWA BasicsBack to JavaScript Course curriculum