Name
== — NN 2 IE J1 ECMA 1
Synopsis
The equality operator. This operator compares two operand values and
returns a Boolean result. The behavior of this operator differs with
the version of JavaScript specified for the SCRIPT
element. If the LANGUAGE
attribute is set to
JavaScript
or JavaScript1.1
,
some operands are automatically converted as shown in the following
table:
Left Operand |
Right Operand |
Description |
---|---|---|
Object reference |
Object reference |
Compare evaluation of object references. |
Any data type |
|
Convert left operand to its object type and compare against null . |
Object reference |
String |
Convert object to string (via |
String |
Number |
Convert string to a number and compare numeric values. |
Version 1 of ECMAScript observes the same behavior.
The situation is a bit different in Navigator when the
SCRIPT
element is set to
LANGUAGE="JavaScript11.2"
. The browser is more
literal about equality, meaning that no automatic data conversions
are performed. Therefore, whereas the expression:
123 == "123"
evaluates to true
in most situations due to
automatic data type conversion, the expression evaluates to
false
in Navigator 4 but only in statements
belonging to explicitly JavaScript 1.2 scripts. Internet Explorer
4’s equivalent of unconverted equality comparison is the
identity operator (===
).
Regardless of version, if you wish to compare the values of objects
(for example, strings explicitly generated with the
new
String()
constructor), you need ...
Get Dynamic HTML: The Definitive Reference now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.