Code Smell 69 - Big Bang (JavaScript Ridiculous Castings)

Code Smell 69 - Big Bang (JavaScript Ridiculous Castings)

This handy operator is a trouble maker.

Maxi Contieri
·May 4, 2021·

1 min read

Subscribe to my newsletter and never miss my upcoming articles

Play this article

TL;DR: Don't mix booleans with non-booleans.


  • Not Declarative Code

  • Hard to debug

  • Magic Castings

  • Accidental Complexity


  1. Be Explicit

  2. Don't mix Booleans with non-booleans.

  3. Fail Fast

  4. Be Smarter than your compiler.

  5. Stay loyal to the bijection.

Sample Code




Since this is a "feature" in some languages it would be hard to test. We can set programming policies or choose more strict languages.

We should detect ! !! usages in non-boolean objects and warn our programmers.


  • Casting

  • Coercion

  • Javascript


Languages like JavaScript divide their whole universe into true or false values. This decision hides errors when dealing with non booleans.

We should be very strict and keep booleans (and their behavior), far away from non booleans.


More info


Photo by Greg Rakozy on Unsplash

It is easier to write an incorrect program than understand a correct one.

Alan J Perlis

This article is part of the CodeSmell Series.

Share this


Technical Opinions are my own. I don't have the revealed truth.

Software Design is a creative activity. These are hints and not rigid rules.

I write on BackEnd Business Systems and OOP Design. My advice/experience might not suit other systems.

You can write me at info(at)