Comparison operators compare Boolean expressions and return a Boolean result.

Below is a list of Comparison Operators.

Operator | PHP | JS | ASP | Description |
---|---|---|---|---|

Equal |
x == y | x == y | True if x is equal to y | |

Identical |
x === y | x === y | x = y | True if x is equal to y and both are of same type |

Not Equal |
x != y | x != y | True if either x is not equal to y | |

x <> y | ||||

Not identical |
x !== y | x !== y | x <> y | True if x is not equal to y, or they are not of same type |

Greater than |
x > y | x > y | x > y | True if x is greater than y |

Less than |
x < y | x < y | x < y | True if x is less than y |

Greater than or equal to |
x >= y | x >= y | x >= y | True if x is greater than or equal to y |

Less than or equal to |
x <= y | x <= y | x <= y | True if x is less than or equal to y |

*Note: In ASP, the operators we say Equal and Not Equal are actually Identical and Not Identical operators respectively.

Let’s say:

a = 5; b = 10; c = 5; d = 11; e = “5”;

**Equal**

This operator will return true when the values being compared are equal.

- If we compare a and c using equal operator then it will return true because the values of a and c are same.
- If we compare a and b using equal operator then it will return false because a and b are not same.
- If we compare a and e using equal operator, it will return true because they are same in value. Equal operator won’t compare data type.

**Identical**

This operator will return true only if the values are equal and of same data type.

- If we compare a and c using Identical operator then it will return true because a and c both has same value (5) and they are same data type (integer).
- If we compare a and b using Identical operator then it will return false because a and b are not having same value.
- If we compare a and e using Identical operator then it will return false as a and e are same in value (5) but they are not of same data type. a is number whereas e is string.

**Not Equal**

This operator will return true when the values being compared are not equal in value.

- If we compare a and c, it will return false as they are equal in value.
- If we compare a and b, it will return true as they are not equal in value.
- If we compare a and e, it will return false as they are equal in value.

**Not Identical**

This operator will return true when the values being compared are equal neither in values nor in data type.

- If we compare a and c then it will return false as a and c are equal both in value and data type.
- If we compare a and b then it will return true as the values for a and b are not equal.
- If we compare a and e then it will return true because a and e are equal in value but they are not equal in data type.

**Greater than**

This operator will return true when the value before greater than sign (>) is greater than the value after greater than sign (>).

- If we check (a > c), it will return false because a and c are equal.
- If we check (a > b), it will return false because a is less than b.
- If we check (b > a), it will return true because b is greater than a.

**Less than**

This operator will return true when the value before less than sign (<) is less than the value after less than sign (<).

- If we check (a < c), it will return false because a and c are equal.
- If we check (a < b), it will return true because a is less than b.
- If we check (b < a), it will return false because b is greater than a.

**Greater than or equal to**

This operator will return true when the value before greater than or equal to sign (>=) is greater than the value after the greater than or equal to sign (>=) or values on both are same.

- If we check (a >= c), it will return true because a and c are equal.
- If we check (a >= b), it will return false because a is neither greater nor equal to b. a is less than b.
- If we check (b >= a), it will return true because b is greater than a.

**Less than or equal to**

This operator will return true when the value before less than or equal to sign (<=) is less than the value after the less than or equal to sign (<=) or values on both are same.

- If we check (a <= c), it will return true because a and c are equal.
- If we check (a <= b), it will return true because a is less than to b.
- If we check (b <= a), it will return false because b is neither less nor equal to a. b is greater than a.

**Summary**

Operator | PHP | JS | ASP | Result |

Equal |
a == c | a == c | True | |

a == b | a == b | False | ||

a == e | a == e | True | ||

Identical |
a === c | a === c | a = c | True |

a === b | a === b | a = b | False | |

a === e | a === e | a = e | False | |

Not Equal |
a != c | a != c | False | |

a != b | a != b | True | ||

a != e | a != e | False | ||

Not identical |
a !== c | a !== c | a <> c | False |

a !== b | a !== b | a <> b | True | |

a !== e | a !== e | a <> e | True | |

Greater than |
a > c | a > c | a > c | False |

a > b | a > b | a > b | False | |

b > a | b > a | b > a | True | |

Less than |
a < c | a < c | a < c | False |

a < b | a < b | a < b | True | |

b < a | b < a | b < a | False | |

Greater than or equal to |
a >= c | a >= c | a >= c | True |

a >= b | a >= b | a >= b | False | |

b >=a | b >=a | b >=a | True | |

Less than or equal to |
a <= c | a <= c | a <= c | True |

a <= b | a <= b | a <= b | True | |

b <=a | b <=a | b <=a | False |

I hope you like this post. If you have any confusion, please let me know in comments. You can read about other types of operators below:

## Leave a Reply