//
function factorial1(n,total) {
if (n === 1) {
return total;
}
return factorial1(n - 1, n * total);
}
//
function factorial2(n) {
if (n === 1) {
return 1;
}
return n * factorial2(n - 1);
}
console.log(factorial1(25,1)); // 1.5511210043330984e+25
console.log(factorial2(25)); // 1.5511210043330986e+25
when the value of n is relatively large, such as 25, the result begins to be abnormal, and the result calculated by non-tail recursion is correct.
what"s wrong with this?