Saturday, January 24, 2026
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

2 COMMENTS

Most Popular

Dominic
32475 POSTS0 COMMENTS
Milvus
122 POSTS0 COMMENTS
Nango Kala
6847 POSTS0 COMMENTS
Nicole Veronica
11977 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12065 POSTS0 COMMENTS
Shaida Kate Naidoo
6986 POSTS0 COMMENTS
Ted Musemwa
7221 POSTS0 COMMENTS
Thapelo Manthata
6934 POSTS0 COMMENTS
Umr Jansen
6912 POSTS0 COMMENTS