The == Operator Lacks Transitivity in JavaScript
In mathematics “is equal to”, equality is a transitive relation meaning that
if a = b and b = c, then a = c
Be aware that the ==
operator lacks transitivity in JavaScript.
Consider the following example where a = '0'
, b = 0
and c = ''
'0' == 0 //true
0 == '' //true
'0' == '' //false
Don’t use the ==
operator, use the ===
operator for equality instead.
'0' === 0 //false
0 === '' //false
'0' === '' //false
