DEV Community

Discussion on: Writing better conditional expressions in JavaScript

Collapse
 
moopet profile image
Ben Sinclair • Edited

I find short circuits, destructuring and arrow functions seriously hamper javascript's readability.

When I read desrtuctured parameters like:

function test({name} = {}) { 
Enter fullscreen mode Exit fullscreen mode

or shorted function calls, like:

mapping[key] && mapping[key]();
Enter fullscreen mode Exit fullscreen mode

or arrow functions without parens, like:

const isAnimal = animal => {
Enter fullscreen mode Exit fullscreen mode

They all make me have to stop and think, "what does this do?" They're too similar in appearance to other forms that it's getting harder and harder to scan through code.

I use a lot of these techniques myself (though I rarely work in Javascript) but I favour readability rather than trying to achieve as few characters as possible.

Collapse
 
anubra266 profile image
Abraham

Shorter code has better readability, given you use good naming conditions.

Collapse
 
moopet profile image
Ben Sinclair

Sometimes it does, sometimes it doesn't; I don't think you can say that as a rule.

Thread Thread
 
anubra266 profile image
Abraham

True...I just think there's more pros on that note.

Collapse
 
anubra266 profile image
Abraham
Collapse
 
darkain profile image
Vincent Milum Jr

We've essentially gotten to the point where we use more symbols than statements, which is becoming worse than ASM.