JavaScript Event Loop Trainer
An interactive trainer that helps you understand the order in which JavaScript code runs: synchronous calls, microtasks, timers, and async/await.
How to practice
- Pick a difficulty level and a topic.
- Predict the order of console.log values.
- Check your answer and explore the step-by-step visualization of the Call Stack, Microtask Queue, and Task Queue.
Topics
Promise.then, Promise.finally, queueMicrotask, setTimeout, async/await, nested callbacks, and task queues.
FAQ
Why does setTimeout with zero delay run after Promise.then?
A setTimeout callback goes to the macrotask queue, while Promise.then goes to the microtask queue. The engine drains all microtasks before the first macrotask.
Which run first: microtasks or macrotasks?
Microtasks: their queue is fully emptied after synchronous code and after every macrotask.
What happens to an async function after await?
The function pauses, and the code after await runs as a microtask.
Тренируйте порядок выполнения JavaScript-кода: синхронные вызовы, микрозадачи, таймеры и async/await. Русская версия.