Photo by Yosuke Ota on Unsplash

Article

JavaScript under the hood

Your code runs inside an engine, the engine runs inside a host, and the host decides when your code runs at all. This overview maps those layers, follows one small program through all of them, and points to the chapter that takes each layer apart.

Article

From source code to machine code

An engine has to start running code within milliseconds and still end up with fast machine code for the functions that matter. This chapter follows a function through V8's parser, interpreter, and three compilers, shows how type feedback drives optimization, and explains why optimized code gets thrown away.

Article

Hidden classes and inline caches

In the language, an object is a bag of named properties that can change at any time. Engines make property access fast anyway by giving objects hidden shapes and caching what each access site has seen. This chapter shows how shapes form, what breaks them, how arrays get the same treatment, and how to check it yourself.

Article

Execution contexts and the call stack

Every running piece of code has an execution context that says where its variables are, what this is, and which realm's built-ins it sees. This chapter follows contexts onto and off the call stack, explains hoisting, closures, suspension, and realms in those terms, and shows how to read the stack traces that come out of it.

Article

The event loop, tasks, and microtasks

The event loop is what turns one thread into a responsive program: it picks a task, runs it to completion, drains the microtasks, and gives the browser a chance to render. This chapter walks one turn of the loop, predicts the output of ordering puzzles from first principles, and shows where Node's loop differs.

Article

Breaking up long tasks

A page that ignores clicks for a moment, a spinner that never appears, or a poor Interaction to Next Paint score usually has one cause: a single task holding the main thread. This page shows how to confirm it, why await alone does not help, and the three fixes — yield, defer, or move the work.

Article

Memory management and garbage collection

JavaScript gives you no way to free memory, only ways to stop referring to it. This chapter explains what the heap holds, how a tracing collector decides what is garbage, why V8 splits the heap into generations, how heap limits and weak references work, and why cleanup of files and sockets cannot be left to the collector.

Article

Finding memory leaks

A JavaScript leak is memory the program can still reach but will never use again. This page is the procedure for finding one: confirm the growth survives garbage collection, use heap snapshots to find what is retained and by what, then fix the reference. It ends with the causes behind most leaks.

Article

Concurrency with workers

Workers are how JavaScript runs in parallel: each one is a separate thread with its own heap and event loop, talking to the others through messages. This chapter covers starting workers in browsers and Node, what copying, transferring, and sharing memory each cost, and which kind of worker fits which job.

Article

JavaScript engine glossary

The Under the Hood series uses terms from three sources: the ECMAScript specification, the HTML Standard's event loop, and the engines' own documentation. This glossary defines each of them in a sentence or two, grouped by topic, and links to the chapter that explains it.

Tags

Search articles

Type a word to search published articles.

Open the search page