if, if else and else syntax in JavaScript

Syntax 1 (if)


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

Syntax 2 (if..else)


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
}

Syntax 3 (if..else if..else)

 if (condition1) {

  //  block of code to be executed if condition1 is true
else if (condition2) {
  //  block of code to be executed if the condition1 is false and condition2 is true
else {
  //  block of code to be executed if the condition1 is false and condition2 is false
}



Comments