01/03/2026
JavaScript Event Loop Explained in 30 Seconds π€― | Promise vs setTimeout
π₯ Explanation (Minimal & Clear)
JavaScript is single-threaded β uses Event Loop.
Promise = Microtask
Runs before setTimeout.
Microtasks have higher priority.
setTimeout = Macrotask
Even with 0ms, it waits.
Goes to Task Queue.
Ex*****on order:
Run all synchronous code first.
Then run Microtasks (Promise).
Then run Macrotasks (setTimeout) in order added.
So:
promise runs first.
Then first timeout1
Then timeout2
Then last timeout1