This is a 1 min read ยท Published on 20 Feb 2021

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")
}

Subscribe to my email list!

Let me be real with you. Sometimes when I'm bored I log in to Buttondown and look at the audience number. If it's bigger than it was the week before, well that makes me feel really happy! I promise I'll never spam you and I will, at most, send you a monthly update with what's happening on this site.