sanjar-notes / javascript

My understanding of JavaScript
0 stars 0 forks source link

JS is single threaded but it's environment doesn't need to be so #8

Open sanjarcode opened 2 years ago

sanjarcode commented 2 years ago

Both Chrome and Node.js provide a potential* multihreaded environment which is controlled by JS (which is single threaded).

sanjarcode commented 2 years ago

Tutorials and books introduce JS as single threaded, but do so with such vigor that they fail to make a distinction between the language and it's running environment.

sanjarcode commented 2 years ago
sanjarcode commented 2 years ago

This fact is pretty obvious since asynchrony with a single processing agent is the same as being single threaded, except when doing round robin.

sanjarcode commented 2 years ago

Clearest video for Node.js asynchronous nature, processes, threads and thread pool

sanjarcode commented 2 years ago

Akshay Saini - event loop and asynchronous nature of JS this video, indirectly, shows that async tasks are handled inside the JS environment, and then into the queue, and from there into the stack via the event loop.