One of two things happens when we call multiply(arr, n).
Case 1: n < 1 and we return 1
Case 2: n >= 1 and we return multiply(arr, n - 1) * arr[n - 1]
In the first case, we return a number.
In the second case, we have a number multiplied by the result of multiply(arr, n - 1), but that will also be a number.
Lets, see an example:
We call
multiply([2, 5, 4], 3)
We are in Case 2, so we want to return multiply([2, 5, 4], 2) * 4. But we don’t know what multiply([2, 5, 4], 2) is!
We call
multiply([2, 5, 4], 2)
We are in Case 2, so we want to return multiply([2, 5, 4], 1) * 5. But we don’t know what multiply([2, 5, 4], 1) is!
We call
multiply([2, 5, 4], 1)
We are in Case 2, so we want to return multiply([2, 5, 4], 0) * 2. But we don’t know what multiply([2, 5, 4], 0) is!
We call
multiply([2, 5, 4], 0)
We are in Case 1, so we return 1.
Now we know multiply([2, 5, 4], 0) == 1.
Now we know multiply([2, 5, 4], 1) returns multiply([2, 5, 4], 0) * 2 == 1 * 2 == 2
Now we know multiply([2, 5, 4], 2) returns multiply([2, 5, 4], 1) * 5 == 2 * 5 == 10
Now we know multiply([2, 5, 4], 3) returns multiply([2, 5, 4], 2) * 4 == 10 * 4 == 40