Search code examples
javascripthtmlweb-worker

Since JavaScript is single-threaded, how are web workers in HTML5 doing multi-threading?


I've been reading about web workers in HTML5, but I know JavaScript is single-threaded.

How are web workers doing multi-threaded work then? or how are they simulating it if it's not truly multi-threaded?


Solution

  • As several comments have already pointed out, Workers really are multi-threaded.

    Some points which may help clarify your thinking:

    • JavaScript is a language, it doesn't define a threading model, it's not necessarily single threaded
    • Most browsers have historically been single threaded (though that is changing rapidly: IE, Chrome, Firefox), and most JavaScript implementations occur in browsers
    • Web Workers are not part of JavaScript, they are a browser feature which can be accessed through JavaScript