Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

javascript
error

RangeError: Maximum call stack size exceeded

Educative Answers Team

In this shot, we will see how to fix the “RangeError: Maximum call stack size exceeded” error.

widget

The most common source for this error is infinite recursion. You must have a recursive function in your code whose base case is not being met and is, therefore, calling the function again and again until you hit the call stack limit.

The following code is an example of infinite recursion, executing it will result in the RangeError:

function foo() {
    foo();
}
foo();

Solution

Use your browser’s console to see which function in your call stack is being repeatedly called. After finding the function, you can easily fix your code by adding a base case.

Other possible reasons

You may also get this if you accidentally import/embed the same JavaScript file twice. To fix this, check the imports in your JS files. You may also find the resources tab of your browser useful.

In older browsers, RangeError also shows up when you try to pass too many arguments to a function that your browser cannot handle.

RELATED TAGS

javascript
error
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring