JavaScript runs synchronous code on the call stack. Promise callbacks enter the microtask queue; timer callbacks enter the task queue. Once the stack empties, the loop drains microtasks first.
The demo moves synchronous code, a Promise callback, and a timer callback in execution order. A timer scheduled for 0 ms still waits behind the current stack and its microtasks.
When to use
Use this model to predict Promise versus timer output and to diagnose UI stalls caused by long synchronous work.