Factorial of a number using Recursion in JavaScript

Finding the factorial of any value using recursion

Source code :

function factorial(n) {
  if (n === 0) {
    return 1;
  }
  
  return n * factorial(n - 1);  //Here's the recursion
}


var n=prompt("Enter the value:");  // Enter any value

alert(factorial(n));



Output :

6

Output :


                

Comments :