DEV Community

Discussion on: ✨♻️ JavaScript Visualized: Event Loop

Collapse
 
ocalde profile image
Oscar Calderon

Hi Lydia. Thanks for taking the time of generating these animations in order to explain it in a very simple way. Still, I have doubts regarding the Call Stack. Is it the same as the main thread in which JS runs? I mean, I understood that, although JS is single threaded, but for the asynchronous logic that gets executed, NodeJS would spawn threads for it while processing the main logic in the single thread. Thanks in advance :)

Collapse
 
avneeshroks profile image
avneeshroks

I think in case of NodeJs, it's just the c++ Api's Insted of web/browser's Api.

Collapse
 
sebasqui profile image
SebasQuiroga

Hi @avneeshroks , I have recently cloned and run the NodeJS code and effectively C/C++ are dominant.
Remember that NodeJS is on top of the V8 engine (the one used in the Chrome browser) that Google opensourced and it is natively written in C++, running in the browser and running in a server are two different environments with different purposes and indeed different APIs. NodeJS is literally running on the same engine than Chrome, but for NodeJS it is not needed to have APIs such as those for the DOM, Window, etc as Chrome needs.

Collapse
 
codefinity profile image
Manav Misra

This is a great ❓, but probably gets a bit more 'low-level' than we need to just understand the behavior of our JS code with relation to the event loop.
However, my understanding is that the JS Engine/Runtime Environment consists of only the stack and the heap. The stack is what is 🏃🏽‍♂️on that single thread. Meanwhile, that message queue is part of the asynchronous browser environment. So, JS's single thread runs through call stack on its single thread and then checks that mesage queue to see what else needs to be done on its thread when it has the chance.