A promise, alone โ€” interactive event loop example

1console.log('start');
2
3Promise.resolve().then(() => {
4 console.log('from the promise');
5});
6
7console.log('end');

The script begins. console.log("start") runs synchronously on the stack.

1 / 6

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

01start

Fig. โ€” A promise, alone ยท step 1 of 6

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