Important Notice:

Complex Conditions using Logical Operators

Complex Conditions using Logical Operators

41 views 1 min read

Complex Conditions using Logical Operators (कॉम्प्लेक्स कंडीशन्स)

हिंदी व्याख्या: एक से ज्यादा शर्तों को एक साथ चेक करने के लिए हम Logical Operators का उपयोग करते हैं:

  • && → AND (दोनों शर्तें सही होनी चाहिए)
  • || → OR (कम से कम एक शर्त सही हो)
  • ! → NOT (शर्त को उलट देता है)
Syntax:-
 
if (condition1 && condition2)
{ // दोनों सही होने पर } if (condition1 || condition2)
{ // कोई एक भी सही होने पर } if (!(condition)) { // शर्त गलत होने पर }
 
 

उदाहरण:

JavaScript
 

let age = 22;

let hasLicense = true;

 let isDrunk = false;

if (age >= 18 && hasLicense && !isDrunk)

 { console.log("You can drive safely."); }

else { console.log("You cannot drive."); }

Output:-
You can drive safely.

English Explanation: Complex conditions are created using Logical Operators:

  • && (AND) → All conditions must be true
  • || (OR) → At least one condition must be true
  • ! (NOT) → Reverses the condition

Related Notes