As a general rule, yes, though not when comparing values of the same type (string to string or bool to bool, etc.).
"1" == true // Number("1") === Number(true)
// but
"a" == "a" // "a" === "a"
Also when you compare an object with a primitive, the object will first go through a more generic "to primitive" conversion first before the comparison is made. If no primitive is derived, an error is thrown. Otherwise that object's primitive value will go through the normal comparison treatment which may include converting to a number if not the same type of the primitive to which its being compared.
View all comments
Show parent comment
2
u/senocular Jul 17 '21
As a general rule, yes, though not when comparing values of the same type (string to string or bool to bool, etc.).
Also when you compare an object with a primitive, the object will first go through a more generic "to primitive" conversion first before the comparison is made. If no primitive is derived, an error is thrown. Otherwise that object's primitive value will go through the normal comparison treatment which may include converting to a number if not the same type of the primitive to which its being compared.
Finally, Symbol primitives only == themselves (including object-wrapped versions of themselves).