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:

Solid Principles For Javascript

SOLID principles for JavaScript

SOLID principles help us keep code flexible. In this article, we’ll examine all of those principles and their implementation using JavaScript.

Frank Joseph
Dec 5, 2024 â‹… 10 min read
Master JavaScript Date And Time: From Moment.js To Temporal

Master JavaScript date and time: From Moment.js to Temporal

JavaScript’s Date API has many limitations. Explore alternative libraries like Moment.js, date-fns, and the new Temporal API.

Yan Sun
Dec 4, 2024 â‹… 9 min read
Npm Vs. Npx: What’s The Difference?

npm vs. npx: What’s the difference?

Explore use cases for using npm vs. npx such as long-term dependency management or temporary tasks and running packages on the fly.

Fimber Elemuwa
Dec 3, 2024 â‹… 5 min read
How To Audit And Validate AI-Generated Code Output

How to audit and validate AI-generated code output

Validating and auditing AI-generated code reduces code errors and ensures that code is compliant.

Boemo Mmopelwa
Dec 2, 2024 â‹… 5 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