• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
August 13, 2022 |2.9K Views
Javascript program to check prime number
  Share  1 Like
Description
Discussion

In this video, we will write a Javascript Program to Check Whether a given number is Prime or not.

Approach 1:

Step 1: First, take the numbers from the user.
Step 2: Then use a for loop and IF-ELSE condition to check whether a number is a prime or not.
Step 3: If it is a prime number, print "True" otherwise "False".

Approach 2:

Here we use Sqrt of N. The reason is that the smallest and greater than one factor of a number cannot be more than the sqrt of N. And we stop as soon as we find a factor.

Javascript program to check whether a number is prime or not:
https://www.geeksforgeeks.org/check-a-number-is-prime-or-not-using-javascript/

Read More