Name
!= — NN 2 IE J1 ECMA 1
Synopsis
The inequality 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 for the equality (==) operator.
Version 1 of ECMAScript observes the same behavior. The situation is
a bit different in Navigator when the SCRIPT
element is set to LANGUAGE="JavaScript1.2". The
browser is more literal about inequality, meaning that no automatic
data conversions are performed. Therefore, whereas the expression:
123 != "123"
evaluates to false in most situations due to
automatic data type conversion, the expression evaluates to
true 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
nonidentity 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 to convert the values beforehand with methods such as
toString() or valueOf().
Example
if (n != m) {
...
}Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access