Skip to content

Home

Factorial of number

Calculates the factorial of a number.

const factorial = n =>
  n < 0
    ? (() => {
        throw new TypeError('Negative numbers are not allowed!');
      })()
    : n <= 1
    ? 1
    : n * factorial(n - 1);

factorial(6); // 720

More like this

Start typing a keyphrase to see matching snippets.