Back to articles

Tag archive

#asyncawait

T
Sep 7, 2026

The JavaScript Event Loop: Why Your Code Doesn't Run the Way You Think

Ever wondered why a Promise resolves before a setTimeout(fn, 0) callback, even though the timeout was scheduled first? This post breaks down the call stack, Web APIs, callback queue, and microtask queue that make up JavaScript's event loop, with a runnable example showing exactly why execution order works the way it does.

Sep 7, 20264 min read0 reactions0 comments