Micro Tasks:

Macro Tasks (or Tasks):

<aside> 💡

The difference in priority between macro tasks and micro tasks can lead to specific execution behaviors. When the call stack is empty, the event loop checks and processes micro tasks before macro tasks. This behavior ensures that micro tasks are executed promptly, which is essential for tasks like promise resolution, making it easier to reason about the order of execution in certain asynchronous scenarios.

Here's a simplified flow of how macro and micro tasks are processed:

  1. Execute code in the call stack.
  2. Check for and execute any available micro tasks in the microtask queue.
  3. Check for and execute any available macro tasks in the task queue.
  4. Repeat steps 2 and 3 as long as there are tasks to process. </aside>