Skip to content

JS If Statements

Syntax

The if statement in JavaScript is used to execute a block of code if a specified condition evaluates to true.

if (condition) {
// Code to execute if condition is true
}

Example

let age = 18;
if (age >= 18) {
console.log("You are eligible to vote.");
}
// Output: You are eligible to vote.