+ 1
In what order does functions work?
function factorial(n) { if (n === 0) { log('Base case reached'); return 1; } log('n - 1 is ' + (n - 1)); return n * factorial(n - 1); } log(factorial(4)); In this small chunk of code, we calculate the factorial of a number. But I have a question: The part where the code goes: return n * factorial(n-1); , does it first count the parenthesis then do the function, or does it input straight "n-1" to the function?
1 ответ
+ 6
It counts it first so that it will be assigned to the arguments.