← All HTML5 Flashcard Decks

HTML5 Web Workers Flashcards

7 cards from real HTML5 practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.

Read the first 7 HTML5 Web Workers flashcards as text
  1. What is a Shared Worker in HTML5, and how does it differ from a Dedicated Worker?

    Answer: A Shared Worker can be accessed by multiple scripts from different windows or tabs of the same origin

    Unlike a Dedicated Worker that is tied to one script, a Shared Worker can be shared across multiple browsing contexts (tabs, iframes) from the same origin.

  2. Which event fires on the main thread when a Web Worker encounters an uncaught error?

    Answer: onerror

    The 'onerror' event handler on the worker instance is triggered when the worker script throws an unhandled exception.

  3. What function is used to import external scripts inside a Web Worker?

    Answer: importScripts('script.js')

    importScripts() is a synchronous function available in worker scope that loads and executes one or more external JavaScript files.

  4. What is the key advantage of using Transferable Objects with postMessage() in Web Workers?

    Answer: The data is transferred by reference (zero-copy), making it much faster for large data like ArrayBuffers

    Transferable Objects like ArrayBuffers are moved (not copied) between threads, so the transfer cost is O(1) regardless of data size.

  5. Which Web Worker type is specifically designed to act as a network proxy and enable offline capabilities?

    Answer: Service Worker

    Service Workers act as a proxy between the browser and network, enabling features like offline caching, push notifications, and background sync.

  6. How do you safely close a Web Worker from within the worker script itself?

    Answer: self.close()

    Inside a worker, self.close() gracefully shuts down the worker, discarding any queued tasks in the event loop.

  7. What does the 'message' event's 'data' property contain when received in a Web Worker?

    Answer: The value passed to postMessage() by the sender, structured-cloned

    The data property on the MessageEvent contains a structured clone of the value passed to postMessage(), supporting complex objects like arrays and objects.