Identically equal to (===) (Operator/identity)

Compares two values for equality and identical type.


ECMAScript edition - 3
JavaScript - 1.3
JScript - 1.0
Internet Explorer - 3.02
Netscape - 4.06
Property/method value type:Boolean primitive
JavaScript syntax:-anOperand1 === anOperand2
Argument list:anOperand1A value of a comparable type
anOperand2A value of the same type as operand 1

The two operands are compared and the Boolean true value is returned if they are equal and of the same type.

The equality operator is not always transitive. For example, two string objects may represent the same string value. Comparing the objects for equality will yield false because the references to the objects are being compared and not the object values themselves. However forcing a string comparison may in fact yield a true value when testing for equality. Do this by converting the objects as part of the comparison process by type conversion or valueOf() methods.

Numeric values may require rounding to take place, and testing for equality may be accurate down to a precision finer than your script cares about. You can set a precision value in a variable, then subtract the value you are comparing with from the absolute value of the comparee. If the difference is smaller than your precision value, then the two values are close enough to yield a match.

The associativity is from left to right.

Refer to the Operator Precedence topic for details of execution order.

The result is the Boolean value true if anOperand1 is numerically or lexically equal to anOperand2 and both operands are of the same type otherwise false is returned.


Example code:

   myObject1 = 100;
   myObject2 = "100";
   if(myObject1 == myObject2)
   document.write("Objects are equal<BR>");
   document.write("Objects are NOT equal<BR>");
   if(myObject1 === myObject2)
   document.write("Objects are identical<BR>");
   document.write("Objects are NOT identical<BR>");

See also:ASCII, Associativity, Equal to (==), Equality expression, Equality operator, Greater than (>), Greater than or equal to (>=), Identity operator, JellyScript, Less than (<), Less than or equal to (<=), Logical expression, Logical operator, NOT Equal to (!=), NOT Identically equal to (!==), Operator Precedence, Relational expression, Relational operator, typeof, Unicode


ECMA 262 edition 3 - section - 11.9.4

O'Reilly JavaScript Definitive Guide - page - 48

Wrox Instant JavaScript - page - 39