Below is a copy/paste from Coderbyte. I'm confused how this works and I'm having trouble finding a suitable answer. Can someone point me in the right direction as to why the child function just automatically inherits the parent function's argument, and is there more going on here than the child function simply not having any arguments and automatically reaching up?
Here is the code.
function FirstFactorial(num) {
// our factorial function
function factorial(n) {
// terminate the recursion once we hit zero
if (n===0) { return 1; }
// otherwise keep calling the function recursively
else { return factorial(n-1) * n; }
}
return factorial(num);
}
FirstFactorial(4);