A comparison operator compares two operands and returns a Boolean value (true or false) as to the validity of the comparison. Operands can be of numeric or string type.
This is the equal operator and returns a boolean true if both the operands are equal. JavaScript will attempt to convert different data types to the same type in order to make the comparison.
a == 2
a == "2"
2 == '2
Assuming 'a' to be 2 and 'b' to be 4, the above examples will return a value of true.
This is the not equal operator which returns a Boolean true if both the operands are not equal. Javascript attempts to convert different data types to the same type before making the comparison.
a != b
a != 4
a != "2"
The above examples return a Boolean true.
This is the strict equal operator and only returns a Boolean true if both the operands are equal and of the same type.
a === 2
b === 4
These above examples return true.
This is the strict not equal operator and only returns a value of true if both the operands are not equal and/or not of the same type.
a !== b
a !== "2"
4 !== '4'
The above examples return a Boolean true.
This is the greater than operator and returns a value of true if the left operand is greater than the right.
a > 1
b > a
This is the greater than or equal operator, which returns true if the first operand is greater than or equal to the second.
a >= 1
a >= 2
b >= a
The above examples return true.
This is the less than operator and returns true if the left operand is less than the right.
a < 3
a < b
This is the less than or equal operator and returns true if the first operand is less than or equal to the second.
a <= 2
a <= 3
a <= b
The above examples all return true.