Conditional statements in JavaScript

learning javascript basics kodementor

Conditional statement are used to perform different operation based on the conditions. In javaScript, there are 3 types of conditional statement.

Types of Conditional Statement in JavaScript

  • if statement,
  • if else statement
  • if..else if..else statement.

Syntax of if statement

You can use if statement if you want to execute a set of code when a condition is true

Example of if statement

Syntax of if…else statement

You can use if…else statement when you want to select one of two sets of lines to execute

Example of if…else if..else statement

Syntax of if…else if…else statement

You can use if…else if…else statement if you want to select one of many sets of lines to execute

Example of if…else statement