Every faktorial call adds a floor to a Gang Kenari house with its own n, the base case answers, then the answers come down floor by floor to the neighbourhood…
Why it matters
Recursion is at the heart of walking trees (the DOM, folders, nested JSON), and “why a stack overflow” stays a mystery while its flow is invisible. Watching the floors go up and come off, and the base case, means understanding when and why recursion works, or blows up.
The key idea
Recursion stacks up first, then answers its way down
Common mistakes
A recursive function runs until Maximum call stack size exceeded The base case was left out. There must always be a stopping condition that is surely reached.
Recursion never reaches the base case although there is one The argument does not head for the base case (a missing n - 1), or jumps over it (n - 2 from an odd number to n === 0). Every call must get closer to the base, and the base must catch every path (n <= 1).
Recursion on very deep data freezes the browser JS in the browser does not optimise tail calls, so its stack is limited (around ten thousand frames). For very deep data, use a loop or an explicit stack.
Try it in this playground
Run faktorial(4) to the end Four floors go up (winding), the base case at faktorial(1), then 1 → 2 → 6 → 24 come down (unwinding).
Watch the first multiplication 2 × 1 is worked out first, 4 × 6 last: the way down is the reverse of the way up.
Take the base case out The house grows until the browser runs out of stack: a RangeError.
The base n === 0 with the step n - 2 From 5, n jumps over 0: the base case is there but never hit.