2021-06-17
1152
#vanilla javascript
Juan Cruz Martinez
53152
Jun 17, 2021 â‹… 4 min read

Refactoring cascading conditionals in favor of readability

Juan Cruz Martinez I'm an entrepreneur, developer, author, speaker, YouTuber, and doer of things.

Recent posts:

how to use the ternary operator in javascript

How to use the ternary operator in JavaScript

Add to your JavaScript knowledge of shortcuts by mastering the ternary operator, so you can write cleaner code that your fellow developers will love.

Chizaram Ken
Feb 21, 2025 â‹… 7 min read
Using tsup To Bundle Your TypeScript Package

Using tsup to bundle your TypeScript package

Learn how to efficiently bundle your TypeScript package with tsup. This guide covers setup, custom output extensions, and best practices for optimized, production-ready builds.

Muhammad Ali
Feb 20, 2025 â‹… 7 min read
how to use react higher order components

How to use React higher-order components

Learn the fundamentals of React’s high-order components and play with some code samples to help you understand how it works.

Hussain Arif
Feb 20, 2025 â‹… 10 min read
dependency inversion principle

Understanding the dependency inversion principle (DIP)

Learn about the dependency inversion principle (DIP), its importance, and how to implement it across multiple programming languages.

Samuel Olusola
Feb 20, 2025 â‹… 8 min read
View all posts

3 Replies to "Refactoring cascading conditionals in favor of readability"

  1. Nice article, just one thing I’m not sure I’d the best advice, particularly to beginners –

    It’s often not considered a best practice to use `&&` and `||` operators as control flow.

    The main priority in code design should be readability, and for someone reading these, it primarily implies just a Boolean expression, rather than control flow. If/else is explicit control flow and so it’s much clearer, particularly when it’s contains side affects.

    Another problem with this approach is that it suggests fewer lines is better, when in some cases, like this one, fewer lines is just increasing the information density, and not making anything clearer.

  2. Excellent suggestions! All small readability improvements that my coworkers and I have been adopting recently. A fun note, for those using typescript and map objects, try using Record.

Leave a Reply