DEV Community

Discussion on: == (or) ===? What do you prefer and why?

Collapse
 
holywar20 profile image
Bryan Winter

If your in a strictly typed environment, using triple equals is essential.

Double equals is more situational. It has it's uses. I've never seen the side-effects people worry about, but maybe my style of coding is clean enough that I actually don't need to worry about type errors.

My big worry with triple equals is in the world of web, you sometimes get unexpected values i'd rather Javascript try to make it work.

I often use an early/escape, early return pattern for validation. I much prefer a loser interpretation here, because loose equality when your taking about validation is actually more 'strict' in terms of defending your application.

ie

if( someNumber == 0 )
   return false

If your getting data from a web request, and something wacky happens in the parsing, I still want the validation method to return false, even if it got a string zero instead of a number zero.