The call stack never lies
Module 1: The Execution Model
The call stack never lies
Every function call is a frame; when the stack is busy nothing else on the thread can interrupt it.
JavaScript runs one statement at a time on one thread. Everything that feels concurrent — animation, fetch responses, click handlers — is choreographed by a loop that decides what runs next. Learn that loop and you can predict behaviour instead of guessing.
1. A frame is pushed when a function is called and popped when it returns — last in, first out, one stack per thread.
2. While a frame is executing there is no preemption: timers, clicks and network data all wait until the stack is empty again.
3. Stack overflow happens when a frame calls itself without a base case — the engine throws once it runs out of room.
console.log("A");
setTimeout(() => console.log("B"), 0);
Promise.resolve().then(() => console.log("C"));
console.log("D");
// A D C Bpredict 01 · commit before reveal
+25 xpA 30ms synchronous function runs inside a click handler. When can a queued timeout callback execute?
| Queue | Lives here | Runs when |
|---|---|---|
| Call stack | synchronous calls | immediately, LIFO |
| Microtasks | promises, queueMicrotask | drained fully after each task |
| Macrotasks | timers, I/O, UI events | one per loop turn |
| Render | style, layout, paint | when the loop lets it |
The call stack never lies — interactive simulator
4-frame windowEvery function call is a frame; when the stack is busy nothing else on the thread can interrupt it.
22ms task → 1 frame dropped
Skipped paint → scroll jank. Split the work or defer it.
mind map · one idea, many anchors
Call stack, queues, rendering opportunities.
memory hook · short trick
Stack, VIP, one, paint
Sync drains first, then the microtask VIP rail empties completely, then exactly one macrotask, then the browser may paint. That sequence never varies.
skill game · 30 seconds · real points
+30 xpWhich habit most improves retention a week after learning something?
Completion gate
45s of active reading left
Verified focus.The timer pauses when this tab loses visibility, so the gate can't be farmed.
Need a break? Bank the streak with an arena duel — timed challenges keep the multiplier alive.