Event Loop is in the core of Node.js, we all have listened this, let just explore how
We all listen Nodejs is single threaded and still manage to perform multiple tasks very easily, hows that possible?
In the above diagram we can see that there is one call-stack, one webAPI, one microtasks queue, one callback queue and one event loop. Now lets explore how it works:-
Now the question is what this hack microtask queue and callback queue is and why we have two queues instead of one?
Lets demystify those, microtasks queue can also be called as a priority queue, so all the task in the microtasks queue is executed first and when the microtasks queue is empty then only task from callback queue is moved to the call-stack to get executed.
Now what all task goes under microtasks queue?
Promise and Mutation Observer goes under microtasks queue and all other callback goes under callback queue.