Reading through a lot of JavaScript Event Loop tutorials, I see different terms to identify the queue stores messages ready to be fetched by the Event Loop when the Call Stack is empty:
I can't find the canonical term to identify this.
Even MDN seems to be confused on the Event Loop page as it calls it Queue first, then says Message Queue but in the tags I see Event Queue.
Is this part of the Loop being defined somewhere in details, or it's simply an implementation detail with no "fixed" name?
A JavaScript runtime uses a message queue, which is a list of messages to be processed. Each message has an associated function that gets called to handle the message. At some point during the event loop, the runtime starts handling the messages on the queue, starting with the oldest one.
Event loop: An event loop is something that pulls stuff out of the queue and places it onto the function execution stack whenever the function stack becomes empty.
Event loop is an endless loop, which waits for tasks, executes them and then sleeps until it receives more tasks. The event loop executes tasks from the event queue only when the call stack is empty i.e. there is no ongoing task. The event loop allows us to use callbacks and promises.
The Callback queue is handled by the JavaScript engine after it has executed all tasks in the microtask queue. Microtask queue is processed after the current task is finished. The Callback queue is processed after the microtask queue is empty. Microtask queue is processed in a separate event loop.
Good question, I'm also a advocate of using proper terminology.
Queue, message queue, and event queue are referring to the same construct (event loop queue). This construct has the callbacks which are fired in the event loop.
Interestingly there are two different queues the job queue and the event loop queue. The job queue is specifically designed for promises. The job queue has a higher priority than the event loop queue, so if there are both callbacks available in both queues the ones in the job queue will be put on the stack first.
Hopefully this answers your question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With