- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript if else Statement
JavaScript Conditions
JavaScript if else Statement
The JavaScript
if elsestatement is used when you want to run one block of code if a condition is true, and another block of code if the condition is false.
Example
Example
javascript
let age = 16;
if (age >= 18) {
console.log("You are eligible.");
} else {
console.log("You are not eligible.");
}In this example, if age is 18 or more, the first message runs. Otherwise, the second message runs.
