Frontend development

Stage 2 · Lesson 8 of 10

The event loop

JavaScript and the browser

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

  • CoursePaid
    Grokking JavaScript Fundamentals

    Design Gurus · Beginner · $50

    Guided beginner course on the language core, with quizzes after every chapter

  • GuideFree
    JavaScript.info

    Ilya Kantor

    Free and thorough: Part 1 for the language, Part 2 for the DOM and events, Part 3 for fetch

Practise

  • Thirty small browser projects with no framework to hide behind

  • Free JavaScript curriculum exercises for daily reps on the language core

Keep handy

  • JavaScript and Web API reference, including fetch, the DOM and events

Also worth your time

Mark this stage as not done?