getting to know the javascript equality operators

Javascript provides a couple of operators for doing equals comparisons and it’s good to know how they differ in functionality.

The equal operator (==) is probably the more commonly used and as we all know returns true if the two values being compared are equal. When the values are of different types it converts them to an appropriate type to do the comparison.

The strict equal (===) returns true if the values are equal and of the same type.

For example:
[1] == 1; //returns true
[1] === 1; //returns false

The not equal (!=) and strict not equal (!==) operators behave similarily for unequal values. According to the Javascript docs the strict operators were added to the language in version 1.3 (current is 1.5).

This can be useful information for those of us who spend time in Authorware script and Actionscript where things are a little bit different.

Leave a Reply