Difference between triple and double equals in JavaScript

JavaScript has both strict and type–converting comparisons. A strict comparison (e.g., ===) is only true if the operands are of the same type and the contents match. The more commonly-used abstract comparison (e.g. ==) converts the operands to the same type before making the comparison.

Equality (==)

The equality operator converts the operands if they are not of the same type, then applies strict comparison. If both operands are objects, then JavaScript compares internal references which are equal when operands refer to the same object in memory.

Inequality (!=)

The inequality operator returns true if the operands are not equal. If the two operands are not of the same type, JavaScript attempts to convert the operands to an appropriate type for the comparison. If both operands are objects, then JavaScript compares internal references which are not equal when operands refer to different objects in memory.

Identity / strict equality (===)

The identity operator returns true if the operands are strictly equal (see above) with no type conversion.

Non-identity / strict inequality (!==)

The non-identity operator returns true if the operands are not equal and/or not of the same type.

Leave a Reply

Your email address will not be published. Required fields are marked *