JavaScript Comparison Operators
Comparison operators are used to compare two values. They return a Boolean: true or false.
1. Equal (==)
Checks if two values are equal (loose comparison).
console.log(5 == "5"); // true
2. Strict Equal (===)
Checks if two values are equal and of the same type.
console.log(5 === "5"); // false
3. Not Equal (!=)
Checks if two values are not equal (loose comparison).
console.log(5 != 3); // true
4. Strict Not Equal (!==)
Checks if two values are not equal or not of the same type.
console.log(5 !== "5"); // true
5. Greater Than (>)
Checks if the left value is greater than the right.
console.log(7 > 3); // true
6. Less Than (<)
Checks if the left value is less than the right.
console.log(7 < 3); // false
7. Greater Than or Equal (>=)
Checks if the left value is greater than or equal to the right.
console.log(5 >= 5); // true
8. Less Than or Equal (<=)
Checks if the left value is less than or equal to the right.
console.log(3 <= 5); // true
Summary Table
Operator | Meaning | Example |
---|---|---|
== | Equal | 5 == "5" |
=== | Strict Equal | 5 === "5" |
!= | Not Equal | 5 != 3 |
!== | Strict Not Equal | 5 !== "5" |
> | Greater Than | 7 > 3 |
< | Less Than | 7 < 3 |
>= | Greater or Equal | 5 >= 5 |
<= | Less or Equal | 3 <= 5 |