JavaScript: conditionals

Conditional statements choose which code runs based on whether an expression is true or false.

What you will learn

Minimal example

const score = 72;
if (score >= 80) {
  console.log('Great');
} else if (score >= 60) {
  console.log('Pass');
} else {
  console.log('Try again');
}

Conditions are evaluated from top to bottom. Once a matching branch runs, the remaining branches are skipped.

Common mistakes