Understanding setTimeout In JavaScript | JS setTimeout In Hindi
JavaScript Spread syntax In Hindi : Spread Operator In JavaScript
session Storage In JavaScript In Hindi | JS session Storage In Hindi
Promise In JavaScript In Hindi | JS Promise constructor
Send Email In Node.JS In Hindi | NodeMailer Example
PHP var_export() Function In Hindi | var_export() In PHP In Hindi
Java program to check if a number is Armstrong : Find Armstrong Number 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.
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 के बारे में अच्छे से समझ गए होंगे।
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