Toolbox-XToolbox-X

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 | undefined

Parameters

  • int (Numeric | undefined): A numeric input value or numeric string whose factorial should be calculated. Can also be undefined.

Return Value

  • number | undefined:
    • The factorial result as a number if the input is valid.
    • undefined if the input is negative, not numeric, non-integer, or undefined.

Example Usage

playground.ts

Notes

  • The function uses a recursive approach internally.
  • Input is normalized before computation.
  • Factorial of 0 and 1 is 1.
  • 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

  • getFactorial
  • calculateFactorial

See Also

Last updated: Sun, Jun 14, 2026 07:06:16AM (UTC)

On this page