🧠 Logical Operators
Last Updated: 11th October 2025
Logical operators are used to combine or invert conditions —
they return true or false depending on logic results.
Hinglish Tip 🗣: Logical operators condition ko jodne ya ulta karne ke kaam aate hain.
Jaise “agar dono sahi hain to kaam karo”, “agar ek bhi sahi hai to chalega”, ya “agar sahi nahi hai to karo”.
🗂 List of Logical Operators
| Operator | Name | Description | Example | Result |
|---|---|---|---|---|
| && | AND | Returns true if both conditions are true | (5 > 2) && (10 > 5) | true |
| || | OR | Returns true if any one condition is true | (3 > 5) || (10 > 7) | true |
| ! | NOT | Reverses the result (true → false, false → true) | !(5 > 2) | false |
✏ Mini Example
let a = 10;
let b = 5;
let c = 7;
console.log(a > b && a > c); // true (both true)
console.log(a > b || a < c); // true (one is true)
console.log(!(a > b)); // false (reverse)
⚙️ Logical Short-Circuiting
Logical operators in JavaScript don’t always return true or false — they return the last evaluated value based on condition.
let a = 10;
let b = 5;
let c = 7;
console.log(a > b && a > c); // true (both true)
console.log(a > b || a < c); // true (one is true)
console.log(!(a > b)); // false (reverse)
Hinglish Tip 🗣: JS me “short-circuit” hota hai — matlab agar pehla hi answer mil gaya, to aage check nahi karta.
💡 Quick Practice
- Check if both conditions x > 5 and y < 10 are true.
- Print "Welcome" if userName exists, using &&.
- Use || to set a default name when user input is empty.
- Write a one-line ternary check for "Even" or "Odd".
- Try null ?? "default" and undefined ?? "fallback" in console.
- Exercises Set 1
- Exercises Set 2