Lets back way, way up.
const countArray = countup(n - 1);
const newLength = countArray.push(n);
Here, on the first line you create an array and call it countArray
.
On the second line, you call push
on this new array.
What does push
do? Well, lets carefully read the documentation.
The push()
method of Array
instances adds the specified elements to the end of an array and returns the new length of the array.
Ok, looks like two things happen.
First, n
is going to be added to the end of the countArray
.
Then, the new length of the array is returned.
A length is going to be something like 2 or 5 or something like that. Those look like numbers to me.
But, we don’t have to guess. We could either run some code and check, or read the documentation:
The length
data property of an Array
instance represents the number of elements in that array. The value is an unsigned, 32-bit integer that is always numerically greater than the highest index in the array.
Looks like the length is a number, for sure.
You cannot call push
on a number, or reverse
.
But in your original code you were trying to call an array method on the return value from calling push
: