Async & Browser JS / Web APIs
Web APIs
Timers, fetch, and DOM events aren't part of JavaScript itself — the browser provides them.
`setTimeout`, `fetch`, and DOM event listeners aren't defined by the JavaScript language — they're provided by the browser (or Node.js) as Web APIs, running outside the single JS thread. JavaScript just calls them and hands over a callback; the environment does the actual waiting, and only pushes the callback back into a queue once it's ready to run.
Codeeditable — Run executes your edits
Loading...
Console
Output will appear here
Visualization
State
Step through — the console panel shows what's happening
Why?
setTimeout returns immediately after registering the timer with the browser — the actual waiting happens outside JavaScript entirely, which is why the two synchronous logs both finish first.