I won’t give a detailed text explanation, just write the code directly, it’s very clear.
<script> function sum(num){ if(num<=1){ return 1; }else{ return num*sum(num-1); //return num*arguments.callee(num-1); //指针 //return 2; } } var sum1=sum; alert(sum1(2)); </script>
The above code is prone to problems when executed. We introduce a method for execution, arguments.callee, which is a pointer to the function being executed. Using pointers instead of function names makes it less likely to go wrong when executing the above code!
The above code is a note on the usage of recursive functions in JavaScript. I hope it will be helpful to everyone.