About Lesson
if, else if, else
The if, else if, and else statements are used for decision-making in JavaScript.
- if: Executes a block of code if the condition is true.
- else if: Tests additional conditions if the previous conditions are false.
- else: Executes a block of code if none of the previous conditions are true.
Example:
JavaScript
let age = 20;
if (age < 18) {
console.log("You are a minor.");
} else if (age < 60) {
console.log("You are an adult.");
} else {
console.log("You are a senior citizen.");
}