+ 1

Why i don't getting the right output when using console.log instead of return?

https://code.sololearn.com/WMA4dP2Lv73F/?ref=app

1st Jan 2020, 3:24 AM
Raisun Lakra
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
1st Jan 2020, 3:47 AM
Rain
Rain - avatar
+ 2
console.log() outputs to the console. That is all. return returns values from a function.
1st Jan 2020, 6:04 AM
Rain
Rain - avatar
+ 1
Because you are returning nothing.
1st Jan 2020, 5:54 AM
Rain
Rain - avatar
+ 1
Outputting to the console. That's all. It doesn't return anything.
1st Jan 2020, 5:57 AM
Rain
Rain - avatar
+ 1
No, they do different things
1st Jan 2020, 5:59 AM
Rain
Rain - avatar
0
But why the factorial function returns undefined instead of the required thing
1st Jan 2020, 5:53 AM
Raisun Lakra
0
So what is the meaning of console.log(factorial(n-1)*n) and console.log(1) here
1st Jan 2020, 5:56 AM
Raisun Lakra