Comparison

There's another set of operators that all return a Boolean value as a result of the operation. These are the comparison operators. The following table lists them together with example uses:

Operator symbol

Description

Example

==

Equality comparison: Returns true when both operands are equal. The operands are converted to the same type before being compared. Also called loose comparison.

> 1 == 1;
true

> 1 == 2;
false

> 1 == '1';
true

===

Equality and type comparison: Returns true if both operands are equal and of the same type. It's better and safer to compare this way because there's no behind-the-scenes type conversions. It is also called strict comparison.

> 1 === '1';
false

> 1 === 1;
true

!=

Non-equality ...

Get Object-Oriented JavaScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.