Infinite recursion causes the call stack to overflow.
This error occurs when a function calls itself (or calls a chain of functions that eventually call back to it) infinitely, exceeding the engine's maximum call stack depth. Every function call consumes stack space; when it runs out, the JavaScript engine throws this error.
The most common cause is unbounded recursion — a recursive function that never hits its base case, or a base case that is never reachable with the given inputs. It can also happen with circular object references in serialization, or event listeners accidentally re-triggering themselves.
1function countdown(n) {2 console.log(n);3 // Missing base case — this never stops!4 return countdown(n - 1);5}6 7countdown(5);1// Fix 1: Add a proper base case2function countdown(n) {3 if (n <= 0) {4 console.log("Done!");5 return;6 }7 console.log(n);8 return countdown(n - 1);9}10 11countdown(5);12// 5, 4, 3, 2, 1, Done!13 14// Fix 2: Use an iterative approach for large N (avoids stack limits)15function countdownIterative(n) {16 while (n > 0) {17 console.log(n);18 n--;19 }20 console.log("Done!");21}22 23countdownIterative(5);Simulate standard system builds to trigger compiler trace records and track memory crashes locally.
The `countdown` function calls itself with `n - 1` without a base case to stop the recursion. It will keep calling itself: `countdown(5)` → `countdown(4)` → ... → `countdown(-Infinity)`, until the engine's call stack is exhausted.