JavaScript Equality: == vs === Explained
I swear, JavaScript equality is out here trying to gaslight me.
Today, I had a value that printed as 0 in the console… but my if (value == 0) check was somehow skipping.
if(value ==0)Turns out, it was “0" from some form field.
== said “yeah, same same”, I said “nah fam, not today”.
Then my brain went back to the classics that still hurt:
NaN === NaN -> false NaN === NaN → false (who hurt you, NaN?)
typeof null → “object” (bro, we’ve been carrying this L since before I was born)
Get Al-Hussein Abubakar’s stories in your inbox
Join Medium for free to get updates from this writer.
and the one that made me close VS Code for 10 minutes: [] ==![] → true 😭
[]==![]-> trueI eventually wrote the post I needed when I was losing my mind over this stuff years ago:
why == is basically playing matchmaker with types,
Why most of us just live on === now,
the one sneaky situation where loose equality is actually cleaner,
and why Object.is() exists for the people who actually care about -0 vs +0 (not me… yet).
Object.is()If JS equality has ever made you want to throw your laptop into the Gulf of Guinea, tell me your worst one below.
Misery loves company.
I have sat down to write a breakdown with the cursed examples if you want: https://blog.al-husayn.dev/blog/equality-operators
Dropping the link in comments if you’re ready to hate JavaScript a little more today.







