1. 程式人生 > >JavaScript 函式的遞迴呼叫

JavaScript 函式的遞迴呼叫

程式碼示例片段:

<htmL>
    <meta http-equiv="Content-Type" content="text/html" charset="UTF-8">
    <title>遞迴呼叫</title>
    <script type="text/javascript">
         function recursion(num){ //定義遞迴函式
             if(num <= 1){
                 return 1;
             }else{
                 return recursion(num - 1) * num;   //呼叫遞迴函式
             } 
         }
    </script>
    <body>
        <script type="text/javascript" >
             document.write("11! = "+recursion(11)); 
        </script>
    </body>
</htmL>