JavaScript Program to check the age of a user is eligible for voting or not

In this program, you will learn how to check the age of a user who is eligible for voting or not in JavaScript.


if(condition){
    //statement
}else{
    //statement
}

JavaScript Program to check the age of a user is eligible for voting or not

Example: How to find the absolute value of a number in JavaScript

let age = prompt("Enter age of a user")

if (age >= 18){
  console.log("User is valid for voting:" +age)
}else{
  console.log("User is not valid for voting:" +age)
}

Output:

Enter age of a user> 20
User is valid for voting:20