Javascript Reference
Categories: Operators

javascript Operators !=

@March 15, 2008, 1:22 a.m.
!= Firefox/Netscape/NN 2 IE 3 ECMA 1  


The inequality 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. The situation is a bit different in Navigator 4 or later 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 and later in statements belonging to explicitly JavaScript 1.2 scripts. Because newer DOM and XHTML standards don't provide a place to specify scripting language versions, you should avoid these special-case situations. If your scripts require tests for absolute inequality of operands, use the newer !== identity operator instead. For typical value inequality testing, the standard inequality operators work perfectly well.


Regardless of version, if you wish to compare the values of objects (for example, strings explicitly generated with the new String( ) constructor), you should compare the values derived from methods such as toString( ) or valueOf( ).

if (n != m) {

Powered by Linode.