JavaScript Object keys, values, entries : Object methods in JS
JavaScript Map In Hindi : Map In JavaScript
Syntax Error In JavaScript In Hindi | JS SyntaxError
Logical Operators In JavaScript In Hindi | JS Logical Operators In Hindi
Promise In JavaScript In Hindi | JS Promise constructor
Time Travel In Snowflake In Hindi | Snowflake Time Travel Example
PHP Form validation | Validate User Input Data In PHP In Hindi
What is TCP/IP Model In Hindi | Layers of TCP/IP Model
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.
इस topic के बारे में बात करने से पहले Nullish Coalescing Oprator के बारे में बात कर लेते हैं।
हम जानते हैं कि Nullish Coalescing Operator का use किसी variable के लिए default value set करना है जैसे -
For Example
let name;
console.log(name ?? "Unknown"); // Unknown
Nullish coalescing operator , सिर्फ value को return करता है फिर चाहे उस value को किसी variable में store करें या direct print कर सकते हैं।
Read more about Nullish coalescing operator...
जबकि, Nullish coalescing assignment operator का use same variable में default value assign करना है , अगर उस variable की value null
या undefined
है। मतलब अगर उस variable में null या undefined हुआ तो default value assign हो जायगी otherwise variable की actual value रहेगी।
For Example :
let name;
name ??= "Unknown";
console.log(name); // Unknown
example में दिए गए expression को अगर आप simplify करोगे तो कुछ इस तरह से होगा।
name = name ?? "Unknown";
इस operator की working ठीक arithmetic assignment like : +=
, -=
, /=
या *=
की तरह ही होती है।
इसे आप कई तरह से use कर सकते हैं , जैसे normal variable या किसी Object या Array के साथ।
For Example :
let fruites = ["Apple", "Banana"];
// in fruites array , we will assign value on index 2
fruites[2] ??= "Papaya";
console.log(fruites);
// with Object.
let user = {
name : 'Rahul'
};
// now address is not in the object.
user.address ??= "UP, India";
console.log(user);
Output
Array(3) [ "Apple", "Banana", "Papaya" ] Object { name: "Rahul", address: "UP, India" }
I Hope, अब आप Nullish coalescing assignment operator के बारे में अच्छे से समझ गए होंगे।
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