If you're looking for the JavaScript if else or if, else, else-if syntax - look no further!


JavaScript If Else Logo

if (1 + 1 === 2) {
  // This one will log
  console.log("Inside the if condition")
} else {
  console.log("Inside the else condition")
}

If you want an if, else, else-if condition in JavaScript it looks like:

if (2 + 1 === 2) {
  console.log("Inside the if condition")
} else if (2 + 1 === 3) {
  // This one will log
  console.log("Inside the else-if condition")
} else {
  console.log("Inside the else condition")
}