@valeriocipolla92, no question are stupid, don’t apologize for being curious
In your mind, how such a process would work?
I’ll explain how it is working now, and hopefully you’ll get why you cannot “just call the function”.
When the engine execute a function, it will add it to the the stack.
You can imagine the stack like a pile of dishes waiting to be cleaned.
You keep adding dished on top, and you start cleaning from top.
(last in, first out).
Imagine I have called the function with these values:
The computer will reach the point where in your body you want to call
rangeOfNumbers (startNum + 1, endNum);
This means that a new function (a “dish” in the pile) is added on top.
So now it moves to the top “dish”
rangeOfNumbers (2, 3);
This cycle continue as all this function keep adding stuff to the pile,
Until you finally reach the “dish”
That function, will
return a value:
This means no more piling stuff, but actually be able to finally remove from it.
So now, the 2nd “dish” will finally receive:
const countArray = 
Meaning that it can go on with its execution:
return countArray; // return 
Now that this function is done, the engine will keep resolving functions as they were added to the pile. Something like:
[1, 2, 3]
Why we cannot simply “call the functions”, without one referencing each other there would be no way for the engine to know that you need that value in another “dish” in the pile, as well as… how exactly can you keep adding data if you don’t keep track of it?
Hope it helps clarify thing better.
There’s also a website that lets you see function executions interactively:
(don’t worry, it supports JS as well).