https://www.jsv9000.app/ - event loop examples
queueMicrotask()?queueMicrotask() lets you schedule a function to run at the end of the current call stack, before any macrotasks like setTimeout. It adds the function to the microtask queue, just like .then() from a resolved Promise.
queueMicrotask(() => {
console.log('This runs after the current call stack, but before setTimeout');
});
✅ Goes into the microtask queue:
Promise.then(...)Promise.catch(...)Promise.finally(...)queueMicrotask(...)MutationObserver callbacks✅ Goes into the macrotask queue:
setTimeout(...)setInterval(...)setImmediate(...) (Node.js only)fetch(...).then(...) → the .then() goes here after the network completesDOM events (e.g., click, input)I/O operations (like reading a file, network responses, etc.)requestAnimationFrame(...) (sort of its own phase — executes before repaints)