Monday, July 27, 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

Most Popular

Dominic
32520 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6903 POSTS0 COMMENTS
Nicole Veronica
12017 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12115 POSTS0 COMMENTS
Shaida Kate Naidoo
7023 POSTS0 COMMENTS
Ted Musemwa
7265 POSTS0 COMMENTS
Thapelo Manthata
6980 POSTS0 COMMENTS
Umr Jansen
6972 POSTS0 COMMENTS