"Maximum call stack size exceeded" in JavaScript — What It Means and How to Fix It
What the JavaScript error "Maximum call stack size exceeded" means and how to fix it.
Published October 29, 2026
The call stack ran out of room, nearly always from infinite or very deep recursion.
What it means and why it happens
Typical causes: missing base case, mutually recursive functions, getters calling themselves or circular JSON.stringify/clone code.
Read the full message: it names the file and line where the problem was detected, which is the best place to start.
What you see
run the code
RangeError: Maximum call stack size exceeded
Practical examples
Code that triggers it
function f() { return f() }
f()The fix
function f(n) {
if (n === 0) return 0
return n + f(n - 1)
}Iterate
let s = 0
for (let i = 1; i <= n; i++) s += iCommon mistakes
- No base case.
- Setter calling itself (this.x = v inside set x).
- Circular structures in recursive utilities.
Key takeaways
- RangeError: Maximum call stack size exceeded: The call stack ran out of room, nearly always from infinite or very deep recursion.
- Read the message and the line number first.
- Fix the cause, don't just silence the error.
FAQ
Can I raise the stack?
Rarely wise; rewrite as a loop.
How do I find which line caused RangeError: Maximum call stack size exceeded?
The error message and stack trace show the file and line; start there and work backwards.