Not understanding this specific par from the solution

Tell us what’s happening:

Can someone please explain the effect of the following, in my codes = rangeOfNumbers(startNum, endNum - 1); numbers.push(endNum);

Your code so far


function rangeOfNumbers(startNum, endNum) {
if (endNum - startNum === 0) {
  return [startNum];
} else {
  var numbers = rangeOfNumbers(startNum, endNum - 1);
  numbers.push(endNum);
  return numbers;
}
}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.113 Safari/537.36.

Challenge: Use Recursion to Create a Range of Numbers

Link to the challenge:

so we first start with a function
a blank function basicly looks like this
function myFunctionName() {
}
We then added two value's that can hold a number and gave them a fitting name.

Then we implemented an if else statement in the code 
if () {
}else {
}
If sets the 1st condition else is about what happens if the if returns Boolean false.
For the first condition we sad aNum minus startNum has to be equal zero
If that is the case it will return and array see the [] which are commonly used to declare an array/object type this is one of the 9 concepts JS reconizes.
Now if this if statement is true it will call up the second vale of itself. It recals it own startNum. After that we close it with a semicolon.
Then comes the else statement which we already exaplained before
else will return a variable called numbers which holds the function we started with. only this time we say that endNum will be minus one
then comes the numbers which we just declared and tell it to push endNum to its back. Push pushes adds a new item to the end of the array we declared befor.
We then return the numbers.

rangeOfNumbers is called recursively.
If there is a possible range then the endNum value is added to the numbers array.

Proof of concept example .
calling your function with 5 and 10

rangeOfNumbers(5, 10)

rangeOfNumbers is called 5 times, see the call stack bellow.
(click on the image to see properly)

So internally this is what is happening:
call rangeOfNumbers(5, 10)
call rangeOfNumbers(5, 9)
call rangeOfNumbers(5, 8)
call rangeOfNumbers(5, 7)
call rangeOfNumbers(5, 6) - this gets evaluated first then previous one and so on(last in first out principle)

Soon as the call stack is prepared to be evaluated, each function call is going to push the value to the numbers array. (rangeOfNumbers has a closure over the numbers value)

Now let’s look at the call stack again when is almost exhausted, have a look at the last execution and the state of the numbers array.

Hope this helps, the magic is the recursive call and the closure over numbers value.