One thing at a time โ€” interactive event loop example

1function makeCoffee() {
2 console.log('coffee ready');
3}
4
5console.log('open the shop');
6makeCoffee();
7console.log('close the shop');

The script runs top to bottom on the call stack. console.log("open the shop") executes and returns immediately.

1 / 7

Call stack

script

Web APIs โ€” browser land

The event loop โ€” is the call stack empty? โ†’ drain the microtask queue first โ†’ then take one callback.

Microtask queue โ€” priority

Callback queue

Console

01open the shop

Fig. โ€” One thing at a time ยท step 1 of 7

โ† โ†’ step ยท space play ยท 123 level