Nullish coalescing assignment In JavaScript In Hindi

Image could not load

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...

JS Nullish coalescing assignment 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 : += , -= , /= या *= की तरह ही होती है।

Nullish coalescing assignment Example

इसे आप कई तरह से 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 के बारे में अच्छे से समझ गए होंगे।

Recent Blogs

Loading ...

Rahul Kumar

Rahul Kumar

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