Let’s start with a simple rule: the normal equality operators == and != are so problematic that you should always use strict equality (=== and !==). Some people say that there are exceptions to this rule, I disagree . Keeping this rule in mind, we can now take a look at what is strange about ==, without burdening our minds unnecessarily.
The “normal” equality operator (==) has many quirks. While it is forgiving, it does not adhere to the typical rules of truthy and falsy (see quirk 1):
> 0 == false // OK
> 1 == true // OK
> 2 == true // not OK
> '' == false // OK
> '1' == true // OK
> '2' == true // not OK
Apart from that, it lets you compare values that aren’t really comparable:
> '' == 0
> '\n 123 \t' == 123
If you are still interested in finding out how exactly == works, you can read up on it here: .
With strict equality (===), values of different types are never equal , which means that all of the above problems go away.