Maximum call stack size exceeded
A function called itself recursively too many times, exceeding the browser's stack limits.
Usually happens because:
- ☑ Missing recursion stopping check
- ☑ Infinite getter/setter loop
- ☑ Circular event trigger
🔍 Quick Checklist:
📊 Where this usually happens (estimated occurrence)
What is Maximum call stack size exceeded?
The V8 engine has a limit on the number of active call stack frames allowed at one time. When a function calls itself recursively without a stopping criteria (base case), the call stack overflows, throwing this RangeError.
Common Causes
- Missing recursive base stopping condition.
- Infinite loops inside event listeners or getter/setter properties.
- Circular object relationships inside deep cloning scripts.
Common Mistakes
- Binding event listeners that trigger each other recursively, resulting in infinite loops.
- Setting object properties inside setter overrides using the same property name.
How to Fix
Framework-Specific Examples
Naming property keys identical to getter definitions creates an infinite lookup loop.
const user = {
get name() {
// Fix: return this._name;
return this.name; // Calls getter again recursively
}
};
try {
console.log(user.name);
} catch (err) {
console.error(err.message); // Maximum call stack size exceeded
}Server Configuration Examples
Checking call stack depth bounds.
# Handled at compiler execution layerBest Practices
- Ensure all recursive pathways have clear, tested exit base returns.
- Favor flat iteration algorithms over recursive structures where applicable.
Frequently Asked Questions (FAQ)
Q: What is the call stack?
The call stack is a mechanism the JavaScript engine uses to keep track of its place in a script that calls multiple functions (which function is currently running and which functions are called from within that function).
Q: How large is the JavaScript call stack limit?
It varies by browser and engine. Typically, the V8 engine limits call stacks to between 10,000 and 50,000 frames. Exceeding this limit triggers the error.
Q: How do I debug infinite recursion?
Analyze the stack trace. It will show the same function name repeated hundreds of times. Add console.logs at the start of the function to inspect variable values.
Q: Does tail call optimization prevent this?
Although part of ES6 specifications, tail call optimization is currently only supported in select browser engines (like Safari/JavaScriptCore). Do not rely on it in cross-browser applications.