Stage 2 · Lesson 8 of 10
The event loop
in the browser runs on one , which also draws the page and handles user input. The is how it juggles all of this. It runs the current code to the end, then all queued microtasks (such as ), then redraws the page if needed.
Then it takes the next task from the task queue, such as a timer or a click. This explains results that look odd at first. setTimeout(fn, 0) runs after promise callbacks.
A loop that takes two seconds freezes the whole page, because nothing else can run meanwhile. It is also the root of INP, the metric for how fast a page responds, which you will measure in the performance stage.
Common trapthinking async code runs in parallel: it only waits in parallel.
A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock
Resources for this stage
Start with· follow one of these
- CoursePaidGrokking JavaScript Fundamentals
Design Gurus · Beginner · $50
Guided beginner course on the language core, with quizzes after every chapter
- GuideFreeJavaScript.info
Ilya Kantor
Free and thorough: Part 1 for the language, Part 2 for the DOM and events, Part 3 for fetch
Practise
Keep handy
Also worth your time
- You Don't Know JS YetGo deeper
For when scope, this, coercion or async behaviour still feel like magic