If Statement in JavaScript


The "if" statement is used to make decisions based on the evaluation of a condition. It allows you to execute a block of code if a given condition is true. If the condition is false, the code inside the "if" block is skipped, and the program continues with the next statement after the "if" block.

Syntax :
         if (condition)
         {
                   // Code to be executed if the condition is true
         }

The "condition" is an expression that evaluates to a Boolean value (true or false). If the condition is true, the code inside the curly braces {} is executed. If the condition is false, the code inside the "if" block is skipped.


Source Code

HTML Code
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Tutor Joes</title>
</head>
<body>
 
	<script src="js/script.js"></script>
</body>
</html>
To download raw file Click Here

script.js
/*
if(condition)
{
    .....
}
*/

let age=prompt("Enter Your Age : ");
if(age!=null && age>=18)
{
  console.log("You are Eligible for Vote..");
}
To download raw file Click Here

List of Programs


JS Practical Questions & Answers


JS Practical Project