Can someone help me understand

While working on the “Use Recursion To Create A Range Of Numbers” challenge I was Able to work out just about the entire solution on my own although I kept receiving the error “maximum call stack exceeded” So I thought that something was wrong with my base case and after tinkering for some time and finally giving up and looking at a solution I realized that the only thing I was missing was the “startNum” in this line:

const numArray = rangeOfNumbers(startNum, endNum - 1); 

Originally I was calling the function with (endNum -1)

I’m just a bit confused on how exactly the absence of the startNum was causing the error “maximum stack call exceeded”.

Here is my solution with the addition of the startNum:

function rangeOfNumbers(startNum, endNum) {

if (endNum === startNum) {

return [startNum];

} else {

const numArray = rangeOfNumbers(startNum, endNum - 1); 


return numArray;



It takes endNum-1 as the start of the array while there is no end to it. It should return an array of integers which begins with first argument in the parentheses and finishes with the second one which is “endNum-1” here.

if you never put the second functions argument this is never true, so function would call itself many many times until the stack call would say that it’s too full and stop the process - never giving an answer

Thank you both najme and ieahleen I can honestly say that i understand the problem and hopefully how I can avoid it in the future, I’m still just a bit upset that I wasnt able to do the challenge 100% on my own, but I really appreciate you two helping me out !