Jobs
Blogs
Courses
Mentorship
Partners
For Employers
e2e logo

JavaScript Conditional Statements

mac

JavaScript Conditional Statements


Conditional statements are used to perform different actions based on different conditions. When you write a code if you want to perform different actions for different decisions. Then you can use conditional statements in your code to do this.

In JavaScript, we have the following conditional statements.

1. if: This conditional statement is used to specify a block of code to be executed if a specified condition is true.

2. else: This conditional statement is used to specify a block of code to be executed if the same condition is false.

3. else if: This conditional statement is used to specify a new condition to test if the first condition is false.

The if Statement

Use the if statement to specify a block of JavaScript code to be executed if a condition is true.

Syntax 

Example

The else Statement

Use the else statement to specify a block of JavaScript code to be executed if a condition is false.

Syntax 

Example

The else if Statement

Use the else if statement to specify a new condition to test if the first condition is false. 

Syntax 

Example