DEV Community

Discussion on: Prove that JavaScript runs in a single thread

Collapse
 
anshulnegitc profile image
Anshul Negi

Thanks for sharing along with practical examples.
If it is single-threaded then how it manages async behaviour?

Collapse
 
rvilgalys profile image
rvilgalys

JS has an event loop that allows for async execution on a single thread (the youtube talk at the end of the post is a great resource on this). IO and garbage collection are actually handled on different threads though.

One advantage here is that other server languages dedicate a new thread per request and so end up bound to hardware limitations for even simple requests at high enough volume. Node.js allows you to scale up as needed (and being single threaded, it's easy to run many instances in parallel).

Collapse
 
anshulnegitc profile image
Anshul Negi

Ooo man I was in such a rush to finish this post that I missed the video link.
Thanks for pointing out.