Getting return undefined on recursive function javascript

前端 未结 4 800
温柔的废话
温柔的废话 2021-01-26 01:58

I heard recursive function is powerful so instead going through loop i tried to create a function which increments a number until it reach certain points. when it reaches i trie

4条回答
  •  时光说笑
    2021-01-26 02:26

    Well you could just use the return statement and you can check the code in the console like

    var i=1;
    function rec(){
    i++;
    console.log(i);
    if(i > 100){
        return i;
    }else{
        return rec();
    }
    }
    
    console.log(rec());
    

提交回复
热议问题