Comparison operators
A comparison operator compares its operands and returns a logical value based on whether the comparison is true. The operands can be numerical, string, logical, or object values. Strings are compared based on standard lexicographical ordering, using Unicode values. In most cases, if the two operands are not of the same type, JavaScript attempts to convert them to an appropriate type for the comparison. This behavior generally results in comparing the operands numerically. The sole exceptions to type conversion within comparisons involve the ===
and !==
operators, which perform strict equality and inequality comparisons. These operators do not attempt to convert the operands to compatible types before checking equality. The following table describes the comparison operators in terms of this sample code:
JSCopy to Clipboard
Operator | Description | Examples returning true |
---|---|---|
Equal ( | Returns |
|
Not equal ( | Returns |
|
Strict equal ( | Returns |
|
Strict not equal ( | Returns |
|
Greater than ( | Returns |
|
Returns |
| |
Less than ( | Returns |
|
Less than or equal ( | Returns |
|
Note: =>
is not a comparison operator but rather is the notation for Arrow functions.
Last updated