Equality and Strict Equality
The difference between == (equality) and === (strict equality) is that the equality operator will coerce values of different types before checking for equality. For example, comparing the string "1" with the number 1 will compare as true. The strict equality operator, on the other hand, will not coerce values to different types, and so the string "1" will not compare as equal to the number 1.
Primitive strings, numbers, and Booleans are compared by value. If they have the same value, they are equal. Objects (including
RegExp objects) compare by reference. Even if two variables of these types have the same value, they are equal only if they refer to exactly the same object.
// Two strings with the same value.
// Two String objects with the same value.
(string1 == string2)
"string1 is equal to string2 <br/>");
"StringObject1 is not equal to StringObject2 <br/>"
// To compare the values of String objects, use the toString()
or valueOf() methods.
(StringObject1.valueOf() == StringObject2.valueOf())
"The value of StringObject1 is equal to the value of
// string1 is equal to string2
// StringObject1 is not equal to StringObject2
// The value of StringObject1 is equal to the value of