Conditional Statements in Java Script

 Conditional Statements in Java Script


Conditional statements are used to perform different actions based on different conditions. In JavaScript, you can use if, else if, and else statements to create these conditions.


Here's an example of an if statement that checks whether a variable is equal to a specific value:


javascript


var age = 18;


if (age < 18) {

  console.log("You are too young to vote.");

} else if (age >= 18 && age < 21) {

  console.log("You can vote but not drink.");

} else {

  console.log("You can vote and drink.");

}

No comments:

Post a Comment

The Importance of Cybersecurity in the Digital Age

 The Importance of Cybersecurity in the Digital Age Introduction: In today's digital age, where technology is deeply intertwined with ev...