Identity operator (Definition)

A close cousin of the equality operator family.

Equality operators are generally used for comparing primitive values.

If they are used for comparing objects, the objects are converted to primitives and then tested. This may not be the test you are trying to accomplish.

Imagine two objects, each distinct from one another but containing the same value in the properties that are yielded by the toString() or valueOf() methods. They are different objects but they will test true for equality.

The identity operators provide a way to test whether they are the same object or not.

There are two identity operators:

You can use these in relational expressions in much the same way as you would the equality operators but remember that you are testing references to objects not values.

See also:Identically equal to (===), NOT Identically equal to (!==)