DEV Community

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

Collapse
 
moopet profile image
Ben Sinclair

I agree it's interesting that you can't drop the braces around function bodies (which hadn't occurred to me before) but the example in the post, of where else if ... is actually else { if ... } seems obvious. Isn't that behaving exactly how it's written, and isn't that how everyone would expect it to work if they'd never seen the language before?

Collapse
 
genta profile image
Fabio Russo • Edited

It's not.
Because we're always encouraged to use {} in some ways, and we learn by memory to use those, without knowing the why.
During the first approach to a language, you cannot be so deeply analytic, because you've to trust the rules, or you will never go on.
After the totally beginner phase, you should start to ask yourself the why.

Thread Thread
 
nathank887 profile image
Nathan

Have you ever encountered a bug caused by missing parentheses? Being consistent improves code readability and makes it easier to identify bugs.

Thread Thread
 
genta profile image
Fabio Russo

It's not about... DON'T USE PARENTHESES :D It's all about know the why of parentheses

Thread Thread
 
develcharlie profile image
DevelCharlie

This proves that grammar in JS is a joke!