DEV Community

Discussion on: βœ”||🀒 Commit or Vomit | nested ternary operator

 
khorne07 profile image
Khorne07

So taking my self by guide, when someone says nested ternaries are hard to understand or using them decrese code readability, my conclusion is that they haven't used ternaries enough, or still don't have enough experience in js, so facing them would be a good way to improve their logic skills and learn a new concise way of write conditional statements blocks

Thread Thread
 
jmdejager profile image
🐀πŸ₯‡ Jasper de Jager

Yes and that's one thing I'm trying to find out with these series ☺️ is it something That's not ok or just something for the more experienced developer. Your comments help a lot!! 😎

Thread Thread
 
tominflux profile image
Tom

It's really not about one's ability to read ternaries. It's about code writing/analysing efficiency. Even a senior dev will be disadvantaged by encountering a complex nested ternary because the context is not explicit and they have to spend some time analysing it. These kind of ternaries always come with a large cognitive load. Always value being concise over ~quick~ readability, and your codebase will become a nightmare to maintain.

Thread Thread
 
jmdejager profile image
🐀πŸ₯‡ Jasper de Jager

I totally agree!

Thread Thread
 
khorne07 profile image
Khorne07

Well that actually depends on the situation. Ternaries are not to include on every conditional situation, that is a horror πŸ˜‚. I'm just saying that I rather use a nested ternary over an if-else block. If there is no need to use an if-else block, then there shouldn't been any nested ternary there either.