Unfortunately despite reading what I have found on line I still do not understand how it works.

here is the code :

```
function countup(n) {
if (n < 1) {
return [];
} else {
const countArray = countup(n - 1);
countArray.push(n);
return countArray;
}
}
console.log(countup(5)); // [ 1, 2, 3, 4, 5 ]
```

The easy part I understand is the one calling the function with n-1 until it reach 0 and then it push [] to the countArray const.

But then I do understand how it had 1 then 2, then 3 etc. to the countArray const as n = 0 and then nothing should happend because the function is not called anymore.

Can someone help me?

As you are not getting the hang of function calls, before diving into recursion, you have to first absolutely understand the following program. I have added comments with full flow as well. Here we are calling one function from another. Recursion is also same but the same function getting called by itself. So first understand the below :-

Let’s go bottom-up approach (when we reach base case of returning empty array) :-

for`n=0`

An empty array

`[]`

gets returned to the`countArray`

where`n`

was 1.So

for,`n=1`

`[].push(1)`

happens and now this array is returned to the`countArray`

where`n`

was 2.So

for n=2,`[1].push(2)`

happens and now this array is returned to the`countArray`

where`n`

was 3.This goes on till

`n=5`

when it all started and also this is where you are logging the final result.The crux is that all this happend while backtracking from

`n=0`

to`n=5`

and not from top to down.Following is the visualization (Starts with going top to bottom and then bottom to top) :-