- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript if Statement
JavaScript Conditions
JavaScript if Statement
The JavaScript
ifstatement is used to run a block of code only when a condition is true.
It helps JavaScript make decisions.
Example
Example
javascript
let age = 20;
if (age >= 18) {
console.log("You are eligible.");
}In this example, the code inside the if block runs only when age is greater than or equal to 18.
What is an if Statement?
An if statement checks a condition.
If the condition is true, JavaScript runs the code inside the curly braces {}.
If the condition is false, JavaScript skips that code.
