⚖️ Comparison Operators
Last Updated: 11th October 2025
Comparison operators are used to compare two values.
They return a Boolean value — true or false.
Hinglish Tip 🗣: Comparison ka matlab — “Dono values barabar hain ya nahi?”, “badi hai ya chhoti?”. Jaise real life me hum kehte hain – 5 bada hai 3 se → yahi comparison hai.
🗂 List of Comparison Operators
| Operator | Name | Example | Result |
|---|---|---|---|
| == | Equal To (checks value only) | 5 == "5" | true ✅ (value same, type ignored) |
| === | Strict Equal (checks value + type) | 5 === "5" | false ❌ (number ≠ string) |
| != | Not Equal (value only) | 10 != "10" | false |
| !== | Strict Not Equal (value + type) | 10 !== "10" | true |
| > | Greater Than | 8 > 5 | true |
| < | Less Than | 3 < 5 | true |
| >= | Greater Than or Equal To | 7 >= 7 | true |
| <= | Less Than or Equal To | 2 <= 5 | true |
✏ Mini Example
let x = 10;
let y = "10";
let z = 5;
console.log(x == y); // true (value same)
console.log(x === y); // false (type different)
console.log(x != y); // false
console.log(x !== y); // true
console.log(x > z); // true
console.log(x <= z); // false
⚠️ Important Difference: == vs ===
| OperaTor | Checks | Example | Result |
|---|---|---|---|
| == | Only value | 5 == "5" | true |
| === | Value + Type (Strict) | 5 === "5" | false |
💡 Always prefer === and !== for safer comparisons in JavaScript.
💡 Quick Practice
- Compare "10" and 10 using both == and ===.
- Check if 15 is greater than or equal to 10.
- Verify if "A" is less than "a" (hint: Unicode value compare hota hai).
- Compare two Boolean values using !==.
- Exercises Set 1
- Exercises Set 2