factorial
Calculates the factorial of a non-negative integer.
Syntax
typescript
factorial(n: number): numberParameters
| Name | Type | Description |
|---|---|---|
n | number | Non-negative integer input. |
Return
| Type | Description |
|---|---|
number | The factorial of n. |
Example
typescript
factorial(5); // 120
factorial(0); // 1Notes
- Throws
TypeErrorifnis not a non-negative integer. - The factorial of 0 is 1 by definition.
