FRONTENDO
Emberhold Forge
0
0
JavaScript · Asynchronous JavaScript
New technique

One smith, many jobs

I'm one dwarf with one pair of hands. While the iron heats, I don't stand and stare: I sharpen the next blade.

JavaScript runs on a single thread: it does one thing at a time. If one job took five seconds, nothing else could happen: no clicks, no scrolling. The page would freeze.

So slow work - timers, network requests - is handed to the browser. JavaScript carries on, and a function runs later, when the result is ready. That's asynchronous code.

The catch: code no longer runs in the order you read it. A line further down can run before a line above it. This lesson is about knowing exactly what runs when.