The identity operator is standardized by ECMAScript v3 and
implemented in JavaScript 1.3 and later. With the introduction of the
identity operator, JavaScript supports =,
==, and === operators. Be sure
you understand the differences between the assignment, equality, and
identity operators, and be careful to use the right one when coding!
Although it is tempting to call all three operators
"equals," it may help to reduce confusion if you read
"gets or is assigned" for =, "is
equal to" for ==, and "is identical
to" for ===.
As an example of testing for equality, consider the comparison:
"1" == true
This expression evaluates to true, indicating that
these very different-looking values are in fact equal. The boolean
value true is first converted to the number 1, and
the comparison is done again. Next, the string "1"
is converted to the number 1. Since both numbers are now the same,
the comparison returns true.
When the equality operator in JavaScript 1.1 attempted to convert a
string to a number and failed, it displayed an error message noting
that the string could not be converted, instead of converting the
string to NaN and returning
false as the result of the comparison. This bug
has been fixed in JavaScript 1.2.