Just curious how this works

Im just curious how this works:

How is it that in this example (the FCC example in the explanation) that the function knows to create an array?

The base case is returning an array.

if (n < 1) {
    return [];
  } 

Try running the code through this and see if it helps.
http://pythontutor.com/javascript.html#mode=edit

I get that the base case is doing that but I thought that the base case is only activated if that condition is met. I dont understand how in this case (the condition is not met) but it’s still activated.

An array is also being created in the following line:

const countArray = countup(n - 1);

When you reach this line the function basically stops while it waits for the call to countup(n - 1) to return. Each time it is called the value is one less than the previous time. So you have a bunch of functions waiting at the same line (basically, waiting in a stack). When you finally get down to 0 then an empty array is returned, and then all of those waiting functions can finally continue (be popped of the stack one by one). The function at the top of the stack (n=1) goes first, adding it’s value of n to the end of the array that was returned and then returns the array. Then the next waiting function (n=2) goes, etc…

Thanks the notion of “stacking” definitely helped me understand the problem better. I ended up solving it.