🚀 Hurry! Offer Ends In
00 Days
00 Hours
00 Mins
00 Secs
Enroll Now
X
Questions


















Write a Java Script program to print Factorial of a given number.

Last Updated : 22 May 2026 Jul 24, Jan 23, Jan 26

Solution:

// JavaScript program to find factorial

let num = 5; // change this value as needed
let fact = 1;

if (num < 0) {
    console.log("Factorial is not defined for negative numbers");
} else {
    for (let i = 1; i <= num; i++) {
        fact = fact * i;
    }
    console.log("Factorial of " + num + " is: " + fact);
}
Verified by Expert
Latest Updates