big numbers factorial js 1

big numbers factorial js

var factorial = function(n){n=BigInt(n);return (n==0n||n==1n)?1n:factorial(n-1n)*n;}
//can be print this way
console.log( factorial(n) );

Here is what the above code is Doing:
1. We are using the BigInt() function to convert the number to a BigInt.
2. We are using the factorial() function to calculate the factorial of a number.
3. We are using the console.log() function to print the result.

Similar Posts