new Worker(url) starts a script in a new agent: its own thread, global object (DedicatedWorkerGlobalScope, reached as self), heap and event loop. The page's main thread keeps handling input and rendering while the worker computes, which is the whole point: a 300 ms loop on the main thread freezes the page for 300 ms; in a worker it doesn't.
The two sides share no objects. They exchange messages: worker.postMessage(data) in the page, postMessage(data) in the worker, each received as a message event. Data is copied by the structured clone algorithm, or transferred for buffers (see the next question). Shared memory exists only through SharedArrayBuffer.
What a worker can't touch: the DOM. There is no window, document, alert() or localStorage, so anything that reads or changes the page has to message the main thread.
What it can use: fetch and XMLHttpRequest, IndexedDB, the Cache API, WebSocket, timers, crypto, BroadcastChannel, OffscreenCanvas, and nested workers.
Since Chrome 80, Firefox 114 and Safari 15, { type: 'module' } makes a module worker: static import, strict mode, no importScripts(). The worker script must be same-origin with the page (a blob: URL works).
An uncaught exception in the worker fires an ErrorEvent at the Worker object in the page. Call preventDefault() on it, or the page reports the error a second time as its own. The worker keeps running.
worker.terminate() stops it at once; close() inside the worker stops it after the current task.
Workers suit CPU-heavy work on data you can send cheaply: parsing, compression, image processing, search indexes. They don't help with work that must touch the DOM, and every worker costs start-up time and a separate heap.