JavaScript#

JavaScript is easy to start and famously easy to be confused by, because a handful of its mechanisms β€” this, closures, coercion, the event loop β€” are invisible until they bite. This page teaches those mechanisms directly. Each section gives you a mental model, an animation of the machine actually doing the work, and the two or three lines you will type this week. Press Play on any animation and step through it; the language tabs let you compare the same idea in JavaScript and Python.

Almost every JavaScript surprise comes from one of four mechanisms: values are compared by reference when they are objects; names are resolved lexically, up the scope chain; this is decided by the call site, not the definition; and anything asynchronous runs after the current script finishes, through a queue. Learn those four and the language stops being surprising.

14 Topics • Mental Models, Interactive Animations & Worked Questions
Unit 1

The Language Core#

Values, variables, objects and functions: the everyday language you write in.

Unit 2

How JavaScript Really Works#

The machinery behind the syntax: the call stack, closures and the prototype chain.

Unit 3

Asynchronous JavaScript#

How one thread handles many things at once: the event loop, promises and async/await.

Unit 4

Modules & the Browser#

Organising code into modules, and putting it to work in the browser.