Thursday, October 16, 2025
HomeLanguagesJavascriptJavaScript InternalError too much recursion

JavaScript InternalError too much recursion

The exception of too much recursion or maximum call stack size exceeded occurs when there are many function calls, or even if a function is missing a base case.

Output message:

Error: Out of stack space (Edge)
InternalError: too much recursion (Firefox)
RangeError: Maximum call stack size exceeded (Chrome)

Error Type:

InternalError

A recursive function is a function that calls itself repeatedly. When a condition is met, the function stops calling itself. This is called a base case. If somehow the condition does not meet then the function continues calling itself and the error occurs.

Example 1: This example works perfectly, without errors. Because the stopping condition is when x >= 5.

Javascript




function recursion(x) {
 
    // Base case
    if (x >= 5)
        return;
    recursion(x + 1); // The recursive call
}
 
function Geeks() {
    try {
        recursion(0);
        console.log("Too much "
            + "recursion error not occurred");
    } catch (e) {
        console.log("Too much "
            + "recursion error occurred");
    }
}
 
Geeks();


Output

Too much recursion error not occurred

Example 2: In this example, the stopping condition is when x >= 1000000000000. This is a large value, so the error occurred.

Javascript




function recursion(x) {
 
    // Base case
    if (x >= 1000000000000)
        return;
    recursion(x + 1); // The recursive call
}
function Geeks() {
    try {
        recursion(0);
        console.log("Too much recursion"
            + " error not occurred");
    } catch (e) {
        console.log("Too much recursion"
            + " error occurred");
    }
}
 
Geeks();


Output

Too much recursion error occurred
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS