A worker runs a script on its own thread and communicates by structured-clone messages. It has no DOM access, which is exactly why it never blocks rendering.
const w = new Worker("/hash-worker.js");
w.postMessage({ data });
w.onmessage = (e) => setResult(e.data);This Code Lab runs your JavaScript inside a worker for that reason: an infinite loop can be terminated without freezing the page.