const factorial = function(n, acc = 1){
if (n < 2) {
return acc;
}
return factorial(n - 1, n * acc);
};
const factorial_normal = function(n){
if (n < 2) {
return 1;
}
return n * factorial_normal(n - 1)
};
console.log(factorial(8956)); // RangeError: Maximum call stack size exceeded
console.log(factorial_normal(8960)); // Infinity
It's just a simple factorial function with javascript. But I got a RangeError with the first function, which i do think it was a better solution cause i think it is faster and more stack-save. Is there something different in these two function that i've ever been known. Please help me, thanks.