Watch the call stack, microtasks and macrotasks interleave.
console.log("1: sync");
setTimeout(() => {
console.log("2: timeout");
}, 0);
Promise.resolve().then(() => {
console.log("3: promise");
});
console.log("4: sync");Script starts on the call stack.
Console
Call Stack
Microtask Queue
Macrotask Queue