
The JavaScript Runtime: Fixing the Mental Model
This article is part of a series on the JavaScript event loop . Most explanations of JavaScript's event loop start with: JavaScript is single-threaded. This statement is technically true but doesn't explain certain behaviors in JavaScript you may have noticed: setTimeout doesn't interrupt loops after the timer has run out setTimeout doesn't block (like sleep(1) in C) A resolved Promise still runs after synchronous code await pauses a function but doesn't freeze the page Rendering sometimes wait So we're left asking: Why didn’t my timeout fire? Why didn’t it interrupt my loop? Why does await pause this but not everything ? Why does nothing ever 'cut in'? In this series, we'll build the understanding needed to make JavaScript stop feeling magical. Today's core claim is simple: JavaScript executes synchronously inside a task, and nothing can interrupt that execution. What Does "Synchronous" and "Asynchronous" Really Mean? First, let's define 'synchronous' and 'asynchronous' precisely. Syn
Continue reading on Dev.to
Opens in a new tab



