🧠 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

OperatorNameDescriptionExampleResult
&&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
!NOTReverses 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

  1. Check if both conditions x > 5 and y < 10 are true.
  2. Print "Welcome" if userName exists, using &&.
  3. Use || to set a default name when user input is empty.
  4. Write a one-line ternary check for "Even" or "Odd".
  5. Try null ?? "default" and undefined ?? "fallback" in console.
  6. Exercises Set 1
  7. Exercises Set 2