[JavaScript]関数の再帰処理をするサンプル

書式
function 関数名(変数名)
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<script>
//関数名
const cft = function funcA(x) {
if (x > 5) {
return;
}
console.log("result:" + x);
++x;
funcA(x); // 再帰処理
}
cft (3);
</script>
<script> //関数名 const cft = function funcA(x) { if (x > 5) { return; } console.log("result:" + x); ++x; funcA(x); // 再帰処理 } cft (3); </script>
<script>
       //関数名
    const cft  = function funcA(x) {
        if (x > 5) {
            return;
        }
        console.log("result:" + x);
        ++x;

        funcA(x); // 再帰処理
    }
    cft (3); 
</script>

実行結果
result:3
result:4
result:5

JavaScript

Posted by arkgame