Decrement in recursion. Javascript

30 Views Asked by At
const factorial = (n) => {
  if (n === 0) return 1;
  return factorial(n - 1) * n;
};
console.log(factorial(5)); //Output: 120


const factorial = (n) => {
  if (n === 0) return 1;
  return factorial(--n) * n;
};
console.log(factorial(5)); //Output: 0

What the difference? Why in the second example i get 0.

0

There are 0 best solutions below