I followed the path of the whole execution and according my calculations it should be return 24, but in fact it returns 7
function factorial(x) {
if (x < 0) return;
if (x === 0) return 1;
return x + 1 * factorial(x - 1);
}
let x = factorial(3);
console.log(x); //7
I´m likely not understand properly the recursive functions
(x + 1) * factorial(x - 1). Multiplication has a higher order of precedence so in your case the expression would work as ifx + (1 * factorial(x - 1))x + 1? The definition of a factorial is justn * (n - 1) * ... * (n - (n -1))- you shouldn't be adding anything.2then twiceNaN7.