Check if a number is prime online

Input

This page allows you to check if a number is prime. Enter a number in the following form, you will instantly know if the number is prime.

Check if
is prime.

Answer

29 is prime.

Reminder

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

Source code

The JavaScript function to check if a number is prime in the above formula is given by:

// Return true if n is prime
function isPrime(n) 
{
    // Check if n is less than 2 => not prime
    if (n<2) return false;

    // Loop from 2 to square root of n
    for (let i = 2; i <= Math.sqrt(n); i++) 
        // If i is a divisor of n, n is not prime
        if (n % i == 0) return false;

    return true;
}

See also


Last update : 03/14/2021