ShareYourGroupShareYourGroupError Explainer

JavaScript RangeError: Maximum call stack size exceeded

A plain-words explanation of this JavaScript message: what it means, the usual causes, and the steps that fix it.

The messageUncaught RangeError: Maximum call stack size exceeded

Make the error yourself

Run in Google Chrome 157.0.8103.51. This is the smallest example we could find that shows it.

JavaScript (in a script tag)

function countdown(n) {
  console.log(n);
  countdown(n - 1);
}
countdown(3);

Browser console (the real message)

RangeError: Maximum call stack size exceeded

Why it happens

Every function call is stored on a stack of waiting calls, and the stack has a limit. A function that calls itself without ever stopping fills it, and the engine stops the program with this error. In the example there is no condition to end the recursion. Other causes: two functions that call each other, a property setter that sets itself (set name(v) { this.name = v }), a toString or toJSON that calls itself, and React or Vue code that updates state inside its own update.

How to fix it

  1. Look at the stack trace: the same function name repeated many times shows the loop.
  2. Add a stopping condition (base case) at the beginning of the function.
  3. For setters, store the value under another name (this._name).
  4. For very deep but valid work, use a loop instead of recursion.

The corrected version

JavaScript (in a script tag)

function countdown(n) {
  if (n < 0) return;
  console.log(n);
  countdown(n - 1);
}
countdown(3);

Browser console (the corrected version)

3
2
1
0

How to avoid it

Write the base case first, and test the function with the smallest input.

Questions

Firefox says "too much recursion". Is it the same?

Yes, it is the same problem worded differently.

This is an independent guide. It is not connected with Python, Microsoft, Google, GitHub or the Git project. Product names belong to their owners. Examples were run on 13 November 2026 in a practice folder or a blank workbook; your version may word a message slightly differently.