Factorial Function: The product of the integers 1 through given number.  

Represented using '!' factorial of 3 will represented as 3!. 

For example, 3! equals 1*2*3 (i.e 6)

function factorial(n)
{
   if (n<=1)
      return 1;
   else
      return n * factorial(n-1);
}

 

How factorial/recursion works: 

e.g.

3! = 3*2!  
  = 3*2*1!  (base case reached)  
  = 3*2*1  (recursion is terminated)