JavaScript Tutorial

Javascript If-else

These conditional statement is used to execute the code whether condition is true or false. There are three forms of if statement in JavaScript:-

  • If Statement
  • If else statement
  • if else if statement

If statement

This type of statement evaluates to execute a block of Javascript code if a condition is true.

Syntax:-

Let’s see the simple example of if statement in javascript.

Input:-

Output:-

If else statement

This conditional statement evaluates the content whether condition is true of false. The syntax of JavaScript if-else statement is given below:-

Syntax:-

Let’s see the simple example of if else statement in javascript.

Input:-

[tryjavascript_example of if else statement in javascript. Input:-]

Output:-

If else if statement

This conditional statement evaluates the content only if expression is true from several expressions. The syntax of JavaScript if else if statement is given below:-

Syntax:-

Let’s see the simple example of if else if statement in javascript:-

Input:-

Output:-


Go back to Previous Course