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

James Drinkard picture James Drinkard · Mar 14, 2012 · Viewed 13.9k times · Source

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

My question is:

How are web workers doing multi-threaded work then? or how are they simulating it if it's not truely multi-threaded? Doesn't seem clear to me here.

Answer

robertc picture robertc · Mar 14, 2012

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