javascriptbrowserevent-loop

What queues actually exist in the event loop


Most sources say that there are two queues in the Event Loop: microtask queue and macrotask queue. But also some sources highlight the third queue (callbacks generated by requestAnimationFrame) and the fourth (callbacks generated by requestIdleCallback). How many queues are there actually, or is this just an implementation detail that may differ from browser to browser?


Solution

  • Your sources probably only list two queues for simplicity, but the event loop has at least four main ones:

    However, there are also other queues depending on the environment, like those for Network events, UI interactions, Garbage Collection, and Web Workers.

    The exact number of queues isn’t set in stone, and it varies based on the JavaScript engine (like V8, SpiderMonkey, or JavaScriptCore).