JavaScript if else syntax

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');
}

Written by Jon Kuperman living in Florida working on Adobe's Creative Cloud. You should follow him on Twitter

Webmentions

00
    Loading Webmentions...

Related Posts

Check out the full archive →

Subscribe to my email list!

Let me be real with you. Sometimes when I'm bored I log in to Mailchimp 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.

© 2021, Jon Kuperman