JavaScript if-else

Last Updated : 28 Jul, 2025

JavaScript conditional statements allow programs to make decisions based on specific conditions. They control the flow of execution, enabling different actions for different scenarios.

JavaScript if-statement

It is a conditional statement that determines whether a specific action or block of code will run based on a condition. If the condition is true, the code executes; if false, it does not.

Syntax

if (condition) {
// Code to be executed if the condition is true
}