Conditional statements in JavaScript

80
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

if (condition) {
    block of code to be executed if the 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

if (condition) {
    block of code to be executed if the condition is true
} else {
    block of code to be executed if the condition is false
}

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


Read More Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.