I was wondering how can I start, join and detach threads in JS.
I saw information about Service Workers, which are meant to run as separate processes in the background, not exactly what I'm looking for. Is there something else? How can I use it?
You probably don't want service workers, but rather web workers (spec | MDN article) on browsers or worker threads on Node.js.
JavaScript in the main window runs on a single thread, it can run asynchronous functions that will turn to progress in the same thread. See:
This two APIs will allow you to run different threads:
Web Workers https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API (run and die kind of script thread execution) example:
var myWorker = new Worker('worker.js');
myWorker.postMessage('Message posted to worker');
Service Workers https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API (run in the background between the network and the application)
fetchwill run asynchronously in their own thread and return a promise.