You are right in saying JS is single threaded.
What it actually means is that the javascript code written is read (parsed
) and evaluated(executed
) by one single process allocated to the browser by the native Operating System.
While there is no restriction in the number of threads that can be given to a browser, but up until some time back, all browsers, mutually used one thread, and which was a safe approach (avoided complex timing issues and cross thread communication).
Since the advent of HTML5, browser makers have been coerced to bring in the cookie features, like Web Workers
.
What web workers allows is for the browser to request more than 1 thread from the OS and execute parallel operations in each of those threads.
Hence it is the responsibility of the developer writing the JS code to make sure the processes have no dependency etc, so that they can actually work independently.
Read up here HTML5 official site about it. Pretty similar to Resig's blog though.