Is all call back placed in event queue

1) function a(b){


2) function b(c){


Just tell me if all execution happening in example 2 similar to example 1
In example 2 what is happening which i explain here.
When function b is involved, it will be pushed into call stack
After that setTimeout function will be involved . As it has a timer, it is moved into Web API . It will be waited till 0 milliseconds. Then call back will be moved into event queue. In event queue call back will be compute it’s execution. Once call stack is empty, event loop placed this call back to call stack for execution. This is what happening in example 2 according to my knowledge.

But in example one there is no setTimeout function. so my doubt is that as there is no setTimeout function declared in example 1, will the call back in function a moved to event queue or call back queue

Is call back queue and event queue same

There’s an event loop that checks if there’s anything in the callback queue and puts it onto the main stack

In 1, it just goes on the stack and executes in order: a gets put on the stack, b gets put on the stack, b executes and pops off, a executes and pops off.

In 2 there’s a setTimeout. b gets put on the stack, c is going to get put in the callback queue, b executes and pops off, c then gets moved back to the stack immediately as the timeout is 0ms, then c executes and pops off

1 Like