Skip to content
techsnow

Control Flow

If...Else

if runs code only when a condition is true.

Syntax:

if (condition) {
  // runs when true
} else if (otherCondition) {
  // runs when the first is false and this is true
} else {
  // runs when nothing above was true
}
const marks = 72;

if (marks >= 80) {
  console.log("Grade A");
} else if (marks >= 60) {
  console.log("Grade B");
} else {
  console.log("Keep practising");
}

Output

Grade B