简体   繁体   中英

Can you help me I want to print the value of factorial 4 but the following function is always giving NAN why?

My question is about recursive function why it is showing always NAN instead of showing the value of factorial 4.

function factorial(i){
              if (i == 1) { return;}  
              return i * factorial(--i);};        
      console.log(factorial(4));
function factorial(i){
              if (i == 1) { return 1;}  
              return i * factorial(--i);};        
      console.log(factorial(4));

if (i == 1) { return;} you should return number hear like return 1;

function factorial(i){
              if (i == 1) { return 1;}  
              return i * factorial(--i);};        
      console.log(factorial(4));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM