JavaScript Error

Maximum Call Stack Size Exceeded

"Maximum call stack size exceeded" is a RangeError thrown when the call stack exceeds the engine's limit, almost always caused by infinite or excessively deep recursion. Each function call adds a frame to the stack, and when the limit is reached, this error is thrown.

Common causes

  • Recursive function without a proper base case
  • Circular references causing infinite traversal
  • Event handlers that re-trigger themselves
  • Getter/setter properties that call themselves
  • Mutually recursive functions without termination

How to fix it

  • Add or fix the base case in recursive functions
  • Convert recursion to iteration using a loop and explicit stack
  • Use trampolining to avoid deep call stacks
  • Check for circular references before recursing
  • Increase recursion limit awareness and use iterative algorithms for large inputs

Example

Maximum Call Stack Size Exceeded example
// Error example: missing base case
function factorial(n) {
  return n * factorial(n - 1);  // Never stops!
}
factorial(5);  // RangeError: Maximum call stack size exceeded

// Fix: add base case
function factorial(n) {
  if (n <= 1) return 1;
  return n * factorial(n - 1);
}

// Fix: use iteration for large inputs
function factorial(n) {
  let result = 1;
  for (let i = 2; i <= n; i++) {
    result *= i;
  }
  return result;
}

Track Maximum Call Stack Size Exceeded with Checkend

Checkend automatically captures Maximum Call Stack Size Exceeded errors in your JavaScript application with full context:

  • Complete stack trace with source maps
  • Browser and environment context
  • Automatic grouping of similar errors
  • Instant notifications when errors occur

Stop debugging in production

Get full error context and fix issues faster with self-hosted error tracking.