re: Compact or Verbose Codestyle? VIEW POST


Two, hands down, with dataObj variable inlined and the method called something more descriptive. One is too obscure. I've been doing JavaScript development for over a decade and every time I have to look up the bizarre JavaScript && and || return logic


I would not call it bizarre and it is not specific to Javascript. You can do this in lots of languages like Java, C++ and even Perl.

The fact that you can use && and || as control structures is a consequence of short circuit evaluation and that is something every programmer should understand.

I do agree that these operators have not been introduced for this purpose and that this style can be less readable.


They are quite handy when you need to get a property nested in an object, like let foo = obj && obj.child && || "", especially when a default fallback value is needed.
But when it's used as a condition, it's a bit annoying and IMO much less readable at first glance.

code of conduct - report abuse