DEV Community

Discussion on: There's no "else if" in JS

Collapse
 
canaanites profile image
Moe Kanan

Isn't the second else supposed to be outside at the same level as the first else?

if(){
}else{
if{}
}else{
return{}
}

Collapse
 
sanderintveld profile image
Sander in 't Veld

No, because that would not result in a meaningful execution branch; if we abstract away the code inside the braces we get

if (condition)
{
  foo();
}
else
{
  bar();
}
else
{
  baz();
}

but what would that mean? When would baz() ever be called?