I have the following recursive program that is called with return type of void. What's being held in memory to cause stack overflow error?
main();
function main() {
neverEnd();
}
function neverEnd() {
console.log("never end");
neverEnd();
}
I have the following recursive program that is called with return type of void. What's being held in memory to cause stack overflow error?
main();
function main() {
neverEnd();
}
function neverEnd() {
console.log("never end");
neverEnd();
}
The program is creating an infinite loop by recursively calling the neverEnd() function without any exit condition. Each time the function is called, a new stack frame is created to store the function call and its local variables. However, since the function never returns, the stack frames keep piling up on the stack until the system runs out of stack memory and throws a stack overflow error.
In summary, the infinite recursion is causing the program to hold an ever-increasing number of stack frames in memory, which leads to the stack overflow error.