SPOILER Confused on how an array is defined using recursion

function rangeOfNumbers(startNum, endNum) {
  if (endNum <= startNum) {
    return [startNum];
  } else {
    var arr = rangeOfNumbers(startNum, endNum - 1);
  return arr;

I’m still new to how recursion works but I finally decided to check the solution and noticed it was only because I was missing [startNum];.

I thought once the loop reached 0 or the startNum I would just need to enter return; to end the loop.

I checked on the debugger. Why does the expression return [startNum]; return an array for the else statement? I noticed without the brackets the var arr does not have an array.

for this to work, you need the function to always return an array, if at one point it has value of undefined (like if you had return;) push will throw an error and everything will stop working

if you need the function to return an array, it always needs to return an array

in other words, what should rangeOfNumbers(5,5) return?

It will return [5]. I’m beginning to get a clear understanding of recursion now. Thank you