Skip to content

isPrime ​

The isPrime function checks if an integer is prime.

Syntax ​

typescript
isPrime(value)

Parameters ​

NameTypeDescription
valuenumberInteger to be checked.

Return Value ​

TypeDescription
booleantrue if the number is prime, else false.

Examples ​

typescript
isPrime(7);  // true
isPrime(10); // false
isPrime(1);  // false

Notes ​

  • Throws a TypeError if the value is not an integer.
  • Prime numbers are greater than 1 and divisible only by 1 and themselves.
  • Useful for mathematical algorithms and cryptography.

References ​

Released under the MIT License.