Equality Operators

Top  Previous  Next

Operators:  ==  !=

Syntax:

expression1 == expression2

equality

expression1 != expression2

inequality

 

The result of the equality operators is either true or false depending on whether the expressions are considered equal:

If both expressions are of type String, then the strings are equal if they are an exact case-sensitive match.

If both expressions are of type Boolean, then they are equal if they are both true or both false.

If both expressions are object or function references, then they are equal if they reference the same object or function.

If both expressions are either undefined or null they are considered equal (e.g., undefined equals null).

Otherwise, the expressions are converted to Number if necessary and their values compared. If either expression is NaN, then they are not equal.

 

The inequality operator != is equivalent to !(expression1 == expression2).