JavaScript Map In Hindi : Map In JavaScript
Understanding setInterval In JavaScript | JS setInterval In Hindi
Optional chaining in JavaScript In Hindi | JS Optional chaining In Hindi
Password Strength Checker In jQuery In Hindi
Generator Functions In JavaScript In Hindi | JavaScript Generator Functions
PHP var_export() Function In Hindi | var_export() In PHP In Hindi
aws s3 kya hai ? | what is aws s3
What is OSI Model In Hindi | Layers of OSI model
Java program to check if string is a palindrome : check palindrome string in java
If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
JavaScript में ternary operator को conditional operator भी कहते हैं , ये only ऐसा operator है जो 3 operands के साथ work करता है। इससे पहले आपने Logical Operators , Nullish Coalescing Operator या Comparison Operators में देखा होगा कि 1 - 2 operands (value) use में लेते थे। लेकिन ternary operator के साथ 3 operands use किये जाते हैं।
जैसा कि इसका नाम है conditional operator , मतलब इसका use condition के bases पर value को manipulate या change करने के लिए किया जाता है।
Conditional / Ternary Operator में हम ( ? :
) use करते हैं , सबसे पहले दिए गए expression / condition को evaluate करते हैं अगर expression true है तो question mark ( ?
) के बाद का statement run होगा और अगर expression / condition false है तो colon ( :
) के बाद वाला statement run होगा।
for example
let res = a ? b : c;
यहां अगर a
की value true
हुई तो b
return होगा otherwise c
return होगा।
Example
let status = 1;
let res = status == 1 ? "Online" : "Offline";
console.log(res);
Online
normally इसे single line if else की तरह use किया जाता है। same example को आप if else से कुछ इस तरह से कर सकते हैं।
let status = 1;
if(status == 1) {
console.log("Online");
}
else {
console.log("Offline");
}
Online
हालाँकि दोनों का result आपको same मिलेगा , लेकिन अगर आपको single line code ही लिखना है तो ternary operator best है।
Logical Operators की तरह ही इसमें भी अगर first operand boolean value नहीं है तो पहले value Internally Boolean value में Type Cast होती है।
will be continue ..
Loading ...
Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)
Get connected with me. :) LinkedIn Twitter Instagram Facebook