We don’t “run” the function several times independently - as the function calls itself BEFORE finishing, the function is “open” several times, also known as recursion-depth
and meaning the function is basically present in the RAM several times, which is why recursions can in fact just break your machine by stackoverflow if no safety is in place.
Now because the function is still “open”, but all it’s variables are local by default → countArray
can have a different value in every instance of the function. So it’s not overriding anything from the previous function.
The recursion calling itself creating a deeper instance of itself will happen first. After all instances are created and we reach the return []
the functions will be executed in reverse order, or from the deepest level back up.