JavaScript engine execute two kinds of tasks in the event loop: macrotask and microtask.
One example of macrotask is event listener callback.
One example of microtask is the then
in a promises.
Js engine event loop has two queues: one queue for the macrotask, another queue for the microtask.
It will execute one things from the macrotask queue, then execute everything on the microtask queue, then perform rerender.
Reference: https://javascript.info/event-loop