Calculate Factorial
Computes the factorial of a non-negative numeric value.
factorial
The factorial function computes the factorial of a non-negative numeric value recursively.
Function Signature
function factorial(int: Numeric | undefined): number | undefinedParameters
int(Numeric | undefined): A numeric input value or numeric string whose factorial should be calculated. Can also beundefined.
Return Value
number | undefined:- The factorial result as a number if the input is valid.
undefinedif the input is negative, not numeric, non-integer, orundefined.
Example Usage
playground.ts
Notes
- The function uses a recursive approach internally.
- Input is normalized before computation.
- Factorial of
0and1is1. - It does not compute factorial for fractions (non-integer values).
- Can return very large values quickly due to the rapid growth rate of factorial values.
Aliases
getFactorialcalculateFactorial
See Also
Last updated: Sun, Jun 14, 2026 07:06:16AM (UTC)
