Loading ...
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.
Nullish coalescing assignment In JavaScript In Hindi
इस 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 के बारे में अच्छे से समझ गए होंगे।
0.
Loading ...
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