+ 1

What is the output of this code?

function a(x){ if(x > 0){ console.log(x * a(x - 1)); }else{ return 1; } } a(3);

6th May 2020, 3:21 PM
Kelechi Ikpo
5 Answers
+ 4
Kelechi Ikpo Oh haha :)) Too clever you are, xD!
6th May 2020, 3:39 PM
Arb Rahim Badsa
Arb Rahim Badsa - avatar
+ 4
Kelechi Ikpo Did you ask that question to test out knowledge? Well wrong place, ask such "test" questions on feed post. Self Answering is considered as offense. I would suggest you to remove the thread from here.
6th May 2020, 3:41 PM
Raj Chhatrala
Raj Chhatrala - avatar
+ 1
Output : 1 NaN NaN Because you are using console.log inside the function and the function itself is a recursive function :)) I think you supposed to write this : function a(x){ if(x > 0){ return x * a(x - 1); }else{ return 1; } } console.log(a(3)); // 6
6th May 2020, 3:31 PM
Arb Rahim Badsa
Arb Rahim Badsa - avatar
0
Thank you Are Rahim Badsa
6th May 2020, 3:42 PM
Kelechi Ikpo
0
Rick Grimes Thank you. I never knew that such is offensive. It actually came out in the path of self discovery that I often fail not because I don't know but as a result of not being careful to read through questions. Thank you for the guidance.
6th May 2020, 3:45 PM
Kelechi Ikpo