Skip to content

factorial

Calculates the factorial of a non-negative integer.

Syntax

typescript
factorial(n: number): number

Parameters

NameTypeDescription
nnumberNon-negative integer input.

Return

TypeDescription
numberThe factorial of n.

Example

typescript
factorial(5); // 120
factorial(0); // 1

Notes

  • Throws TypeError if n is not a non-negative integer.
  • The factorial of 0 is 1 by definition.

References

Released under the MIT License.