SOURCE

function factorial(n) {
    // 出口
    if (n === 1) return 1;
    return n * factorial(n - 1);
}

console.log(factorial(6))


function factorialTCO(n, total) {
  if (n === 1) return total;
  return factorial(n - 1, n * total);
}

console.log(factorialTCO(6, 1))
console.log(6 * 5 * 4 * 3 * 2 * 1)
console 命令行工具 X clear

                    
>
console