Last Updated: May 23, 2019
·
2.83K
· 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 ·

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside