If, Elif, and else statements in JavaScript

How do you use elif statements in JS

Welcome to the forums.

Unlike Python, JavaScript has else if instead of elif.

You can use it like this:

if(condition) {
  code
} else if(condition) {
  code
} else {
  code
}

Note that condition and code are only placeholders.

3 Likes

No, Python has elif structure too:

a = 3
if a < 2:
    print("a < 2")
elif a = 2:
    print("a is 2")
else:
    print("a > 2")

What I meant was that JavaScript has else if, unlike Python who has elif.

3 Likes