philnash@programming.dev to JavaScript@programming.devEnglish · 11 months agoStop nesting ternaries in JavaScriptwww.sonarsource.comexternal-linkmessage-square12fedilinkarrow-up11arrow-down11
arrow-up10arrow-down1external-linkStop nesting ternaries in JavaScriptwww.sonarsource.comphilnash@programming.dev to JavaScript@programming.devEnglish · 11 months agomessage-square12fedilink
minus-squareBrianTheeBiscuiteer@lemmy.worldlinkfedilinkarrow-up1·edit-28 months agoSeems a bit shitty they mention the article by Eric Elliott (one of the first search results if you search “nested ternaries”) but they don’t take his advice. This doesn’t seem ugly to me at all (left out animal so I didn’t have to type as much): const animalType = canBark() && isScary() ? 'wolf' : canBark() ? 'dog' : canMeow() ? 'cat' : 'rabbit';
Seems a bit shitty they mention the article by Eric Elliott (one of the first search results if you search “nested ternaries”) but they don’t take his advice.
This doesn’t seem ugly to me at all (left out
animal
so I didn’t have to type as much):const animalType = canBark() && isScary() ? 'wolf' : canBark() ? 'dog' : canMeow() ? 'cat' : 'rabbit';