home / experts / javascript / column26 |
|
JavaScript 1.3 introduces two new operators, the strict equality operators. The strict equality operators (
Use the strict equality operator ( Comparing two operands may be tricky at times. Comparing numbers is probably the most straightforward. Numbers are equal when they are numerically equal, or to put it differently, the difference between them is zero. Strings are compared according to a standard lexicographical ordering, using Unicode values (see our previous column, JavaScript 1.3 Overview, Part I). Therefore, two strings are equal when they have the same length, same sequence of characters, exactly in the same corresponding positions. The number Two objects are equal if they refer to the exact same
If we duplicate this line to construct two seemingly-identical objects,
a strict equality operator:
will yield
But this behavior of object comparison is valid for standard equality operator as well. The comparison:
returns
returns Comparing a string with a number highlights the difference between strict equality and standard equality operators.
returns
returns true.
Boolean operands are equal if they are both |
Created: September 28, 1998
Revised: September 28, 1998
URL: http://www.webreference.com/js/column26/stricteq.html