Code Smell 69 — Big Bang (JavaScript Ridiculous Castings)
This handy operator is a troublemaker.

TL;DR: Don’t mix booleans with non-booleans.
Problems
Not Declarative Code
Hard to debug
Magic Castings
Accidental Complexity
Solutions
Be Explicit
Don’t mix Booleans with non-booleans.
Be Smarter than your compiler.
Stay loyal to the bijection.
The one and only software design principle
If we build our entire paradigm on a single rule, we can keep it simple and make excellent models.codeburst.io
Sample Code
Wrong
Right
Detection
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.
Tags
Casting
Coercion
Javascript
Conclusion
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.
Relations
Code Smell 24 — Boolean Coercions
Booleans should be just True and falseblog.devgenius.io
Code Smell 06 — Too Clever Programmer
Code difficult to read. Tricky with names without semantic. Sometimes using language’s accidental complexity.blog.devgenius.io
More info
The Double-Bang (!!) Operator And A Misunderstanding Of How JavaScript Handles Truthy / Falsy…
Ben Nadel has noticed developers using the double-bang (!!) operator far more often in their JavaScript code than they…www.bennadel.com
Truthy
In JavaScript, a truthy value is a value that is considered true when encountered in a Boolean context. All values are…developer.mozilla.org
It is easier to write an incorrect program than understand a correct one.
Alan J Perlis
Software Engineering Great Quotes
Sometimes a short thought can bring amazing ideas.blog.devgenius.io
This article is part of the CodeSmell Series.
How to Find the Stinky parts of your Code
The code smells bad. Let’s see how to change the aromas.blog.devgenius.io