Joel Thoms
Jul 30, 2017 · 1 min read

While this might appear as a post that is “doing things different to do things different”. This article has a more subversive intent, which is to subtly promote functional design over imperative design.

This is just one in a series of articles where I try not to overload readers with complicated laws of functional programming. Instead I try to suggest techniques they can readily use in their code today.

There are fundamental differences between using an if statement when compared to a ternary expression.

This is just a very small part of a larger journey into functional design. I have outlined some differences between the if and ternary here:

The if statement though is much more readable for complex stuff.

One thing I have noticed about if statements, is that it allows unnecessary complexity to creep into your code. If you cannot fit your logic into a ternary and require an if statement, that would suggest the code needs to be broken down further.

One this code is properly broken down, it will look like a natural fit for a ternary.

Eliminating if statements will force you to write better code.

I would also recommend this great article by Charles Scalfani

Cheers!

    Joel Thoms

    Written by

    Computer Scientist and Technology Evangelist with 20+ years of experience with JavaScript!

    Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
    Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
    Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade