Primality Test

  • Difficulty: easy

A prime number (or a prime) is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers.

A natural number is any number greater than or equal to 0 that is not a fraction or a decimal

A natural number greater than 1 that is not prime is called a composite number. For example, 5 is prime because the only ways of writing it as a product, 1 × 5 or 5 × 1, involve 5 itself. However, 6 is a composite number because it is the product of two numbers (2 × 3) that are both smaller than 6.

A primality test is an algorithm for determining whether an input number is prime.

This lesson preview is part of the JavaScript Algorithms course and can be unlocked immediately with a \newline Pro subscription or a single-time purchase. Already have access to this course? Log in here.

Unlock This Course

Get unlimited access to JavaScript Algorithms, plus 0+ \newline books, guides and courses with the \newline Pro subscription.

Thumbnail for the \newline course JavaScript Algorithms