# 10 examples of 'factorial of a number in javascript' in JavaScript

Every line of 'factorial of a number in javascript' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

## All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
``5export default function factorial(number) {6  let result = 1;78  for (let i = 2; i &lt;= number; i += 1) {9    result *= i;10  }1112  return result;13}``
``1function factorial(num) {2    if (num === 1) {3      return num;4    } else {5      let hitung = num * factorial(num - 1);6      console.log(hitung);7      return num * factorial(num - 1);8    }9  }``
``3function factorialize(num) {4	if (num&lt;=1) {5		return 1;//0的阶乘为0,同时也是递归出口6	}7  return num*factorialize(num-1);//使用递归8}``
``25function factorialize(num) {26  if (num &lt; 2) {27    return 1;28  }29  return num * factorialize(num - 1);30}``
``194function factorial(num) {195  const f = [];196  function inner(n) {197    if (n === 0 || n === 1) {198      return 1;199    }200    if (f[n] &gt; 0) {201      return f[n];202    }203    return f[n] = inner(n - 1) * n;204  }205  return inner(num);206}``
``2function factorial(a) {3    a = parseInt(a);4    if (a &lt;= 0)5        return 1;6    else7        return a * factorial(a - 1);8}``
``11function factorial(n) {12    if (n &lt; 1) {13        return 1;14    } else {15        return n * factorial(n - 1);16    }17}``
``4function unfactorial(num) {5  var d = 1;6  while (num &gt; 1 &amp;&amp; Math.round(num) === num) {7    d += 1;8    num /= d;9  }10  if (num === 1) return d + "!";11  else return "NONE";12}``
``335function factorial(n) {336    if (n == 0) {337        return 1;338    }339    f = libs.BigInteger.BigInteger.ONE;340    for (var i=1; i&lt;=n; i++) {341        f = f.multiply(new libs.BigInteger.BigInteger(i));342    }343    return f;344}``
``15function factorial(n){16    if ((n == 0) || (n == 1))17        return 1;18    else19        return (n * factorial(n - 1));20}``