Share your knowledge with other learners . . . Write As Guest

Logical Operators In JavaScript In Hindi | JS Logical Operators In Hindi

Top Blogs

Loading ...


Image could not load

JavaScript में logical operators को एक या एक से अधिक boolean values पर apply किये जाते हैं , JavaScript में 4 तरह के logical operators होते हैं -

  1. OR (||)

  2. AND (&&)

  3. NOT (!)

  4. Nullish Coalescing (??)

इस blog में हम पहले 3 operators के बारे में बात करेंगे।

JavaScript OR Operator

OR operator को 2 vertical lines (||) से represent किया जाता है।

अगर दो या दो से अधिक दो गयी conditions में से एक भी condition true होती है , तो आपको true मिलेगा , normally OR operator की truth table कुछ इस तरह से होती।

true || false // true
false || true // true 
false || false // false
true || true // true

जैसा कि आप देख सकते हैं आपको हर condition के लिए true मिकेगा जब तक सभी conditions false नहीं होती।

JavaScript OR Operator Example

console.log(0 || 0); // 0 console.log(0 || null); // null console.log(0 || null || false); // false

ऊपर दिए गए examples को देखकर शायद आप थोड़ा confuse हुए होंगे , कोई बात नहीं इसे step by step समझने का try करते हैं।

1. Logical operators में expressions हमेशा left to right execute होते हैं ।

2. OR operator , पहली true value return करता है , चाहे कितनी ही conditions जो जैसे ही कोई true value मिली same value को return करेगा और उससे आगे का execution रुक जायगा।

Example

console.log(false || 0 || true || "will not execute"); // true

3. अगर expression में आप boolean value के अलावा दूसरी type की values use करेंगे वो values internally boolean value में Type Cast होगीं फिर condition के according evaluation होगा। और type casting के बाद अगर value true है तो वो actual value return होगी।

console.log(false || "" || "Hi" || "Hello"); // Hi console.log("Hello" || false || ""); // Hello

4. अगर एक भी condition true नहीं है तो सबसे last में जो value होगी वो return होती है।

console.log(1 || 0); // 1 console.log(0 || 0); // 0 console.log(0 || null); // null console.log(0 || null || false); // false

JavaScript AND Operator

AND operator को दो ampersands && sign से represent किया जाता है। किसी expression में दी गयी अगर सभी conditions true होती है तो AND operator true return करता है otherwise false .

AND operator के लिए truth table कुछ इस तरह से होगी -

true && false // false false && true // false false && false // false true && true // true

JavaScript AND Operator Example

let marks = prompt("Please enter your marks ?"); marks = parseInt(marks); if(marks >= 90) { console.log("Passed with A+ Grade"); } else if(marks >= 80 && marks < 90) { console.log("Passed with A Grade"); } else { console.log("Passed"); }
More about AND operator

AND operator , OR operator से थोड़ा अलग work करता है -

1. evaluation तो इसमें भी left to right ही होता है।

2. AND operator , पहली false value return करता है , चाहे कितनी ही conditions जो जैसे ही कोई false value मिली same value को return करेगा और उससे आगे का execution रुक जायगा।

console.log(true && 1 && 0 && true); // 0 console.log(true && false && 0 && true); // false console.log(null && false && 0 && true); // null

3. अगर expression में आप boolean value के अलावा दूसरी type की values use करेंगे तो सबसे पहले वो values internally boolean value में Type Cast होगीं फिर condition के according evaluation होगा। और type casting के बाद अगर value false है तो वो actual value return होगी , otherwise आगे की conditions match होगी।

console.log(true && 1 && null && "Hello"); // null

4. अगर expression में दी गयी सभी conditions true है तो सबसे last में जो value return होती है।

console.log(true && 1 && "Hello"); // Hello console.log(true && 1); // 1 console.log(1 && 10); // 10

JavaScript NOT Operator

NOT operator को exclamation sign ! से represent किया जाता , इसे normally किसी single value के साथ use किया जाता है।

true value के साथ use करने पर false और false के साथ use करने पर true return करता है।

console.log(! true) // false console.log(! false) // true

इसके अलावा double exclamation sign !! का use करके boolean type casting भी की जाती है।

console.log(!! "Hi"); // true console.log(!! ""); // false console.log(!! 1); // true console.log(!! 0); // false console.log(!! null); // false console.log(!! undefined); // false

आपको JavaScript में logical operators के बारे में अच्छे से समझ आ गया होगा।

Give Feedback

like-image 0.

Recent Blogs

Loading ...

Rahul Kumar

Rahul Kumar

Hi ! My name is Rahul Kumar Rajput. I'm a back end web developer and founder of learnhindituts.com. I live in Uttar Pradesh (UP), India and I love to talk about programming as well as writing technical tutorials and tips that can help to others.

Get connected with me. :) LinkedIn Twitter Instagram Facebook