+ 1
Why i don't getting the right output when using console.log instead of return?
7 Answers
+ 3
You don't get a number because the factorial function returns undefined. Multiplying undefined by a number is giving back NaN.
Test this by running this code:
let func = function() {
//empty
}
console.log(func());
console.log(func() * 1);
//returns undefined and NaN
+ 2
console.log() outputs to the console. That is all.
return returns values from a function.
+ 1
Because you are returning nothing.
+ 1
Outputting to the console. That's all. It doesn't return anything.
+ 1
No, they do different things
0
But why the factorial function returns undefined instead of the required thing
0
So what is the meaning of console.log(factorial(n-1)*n) and console.log(1) here