...
For example, given that x = 5, the table below explains the comparison operators:
Operator | Description | Comparing | Returns |
---|
== | equal to | x == 8 | false |
x == 5 | true |
x == "5" | true |
=== | equal value and equal type | x === 5 | true |
x === "5" | false |
!= | not equal | x != 8 | true |
!== | not equal value or not equal type | x !== 5 | false |
x !== "5" | true |
x !== 8 | true |
> | greater than | x > 8 | false |
< | less than | x < 8 | true |
>= | greater than or equal to | x >= 8 | false |
<= | less than or equal to | x <= 8 | true |
Oddities of Null
OperatorDescriptionComparingReturnsequal to | 1) | true if x = 1; |
if (x == |
8false | 1) | true if x = '1'; |
if (x == |
50) | true if x = 0; |
if (x == |
"5"0) | true if x = null; |
if (x ==0) | true if x = |
equal value and equal type | x === 5 | true | x === "5" | falseundefined; |
=== | |
---|
if (x ==1) | |
if (x ==1) | |
if (x ==0) | |
if (x ==0) | |
if (x ==0) | |
| |
| |
|
|
false |