The equality operator == compares only the types of the operands.


The equality operator '==' compares only the types of the operands


The equality operator '==' compares only the values of the operands

Here is what's right.

The usual equality operator == compares the values of its operands, allowing some implicit casts to happen.

For example, under these constraints 1 is equal to true even though they are values of different types (respectively, number and boolean).

It would make no sense for this equality operator to claim that two values are equal when just their types match. It is pretty obvious that 1 is not equal to 2, even though they are both of type number.

Where could this misconception come from?

The confusion probably stems from knowing that there exist another operator for equality comparsion that behaves differently.

That operator is called strict equality operator because it also (but not only!) checks that the types of its operand match in order to return true.

Stay up-to-date

Follow us on  twitter to hear about new misconceptions.