• Courses
  • Tutorials
  • DSA
  • Data Science
  • Web Tech
September 15, 2022 |1.2K Views

Javascript program to find factorial of a number

  Share  2 Likes
Description
Discussion

In this video, we will write a Javascript program to find the Factorial of a Number. 

Factorial can be defined as - “ Factorial of a non-negative integer is the multiplication of all integers smaller than or equal to n”. 

For example: 
Factorial of 3 is 3*2*1 which is 6 
Factorial of 5 is 5*4*3*2*1 which is 120. 
Factorial of 8 is 8*7*6* 5*4*3*2*1 which is 40320. 

Here we see 2 different methods for calculating the factorial of any integer number. 

1) Using Integrative loop: In this method, we use a for loop to iterate over the sequence of numbers and get the desired factorial of a number. 

2) Using Recursive function: 
In this method, we are calling the same function more than once to get the factorial of a number. Factorial can be calculated using the following recursive formula. 

n! = n * (n-1)! 
n! = 1 if n = 0 or n = 1

JS program to find Factorial of a number : 
https://www.geeksforgeeks.org/factorial-of-a-number-using-javascript/