Last Updated: May 23, 2019
·
2.62K
· justinhillsjohnson

'else if' in JavaScript is actually a nested 'if' inside an 'else' with optional curly braces omitted

https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Statements/if...else#Description

This:

if (condition1)
    statement1
else if (condition2)
    statement2
else if (condition3)
    statement3

Is effectively:

if (condition1)
    statement1
else
    if (condition2)
        statement2
    else
        if (condition3)
...

1 Response
Add your response

Hm, I thought this was pretty obvious?

over 1 year ago ·