
If a task takes too long, the browser can’t do other tasks, such as processing user events.Changes to the DOM are painted only after the task is complete. It doesn’t matter if the task takes a long time. Rendering never happens while the engine executes a task.When the engine browser is done with the script, it handles mousemove event, then setTimeout handler, and so on. Tasks from the queue are processed on “first come – first served” basis.

The tasks form a queue, so-called “macrotask queue” (v8 term):įor instance, while the engine is busy executing a script, a user may move their mouse causing mousemove, and setTimeout may be due and so on, these tasks form a queue, as illustrated on the picture above. It may happen that a task comes while the engine is busy, then it’s enqueued. Tasks are set – the engine handles them – then waits for more tasks (while sleeping and consuming close to zero CPU).

Browser JavaScript execution flow, as well as in Node.js, is based on an event loop.
