<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rutuja</title>
    <description>The latest articles on DEV Community by Rutuja (@rutuja_web_dev).</description>
    <link>https://dev.to/rutuja_web_dev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2807992%2F7dc30c45-f67e-413b-b3ba-3da4c864a06b.png</url>
      <title>DEV Community: Rutuja</title>
      <link>https://dev.to/rutuja_web_dev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rutuja_web_dev"/>
    <language>en</language>
    <item>
      <title>Understanding the ?? (Nullish Coalescing) Operator vs. || (Logical OR) in JavaScript</title>
      <dc:creator>Rutuja</dc:creator>
      <pubDate>Mon, 03 Feb 2025 08:06:34 +0000</pubDate>
      <link>https://dev.to/rutuja_web_dev/understanding-the-nullish-coalescing-operator-vs-logical-or-in-javascript-5263</link>
      <guid>https://dev.to/rutuja_web_dev/understanding-the-nullish-coalescing-operator-vs-logical-or-in-javascript-5263</guid>
      <description>&lt;p&gt;In JavaScript, the ?? (nullish coalescing operator) is often used as an alternative to the logical OR (||), but with a key difference. While both operators provide a fallback value when the left-hand side is falsy, ?? only considers null and undefined as "falsy" values, whereas || considers all falsy values (like false, 0, NaN, '', null, undefined).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Differences?? (Nullish Coalescing Operator)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let value = null ?? "default"; // "default"
let value2 = undefined ?? "default"; // "default"
let value3 = "" ?? "default"; // "" (because empty string is not null or undefined)
let value4 = 0 ?? "default"; // 0 (because 0 is not null or undefined)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;|| (Logical OR Operator)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let value = null || "default"; // "default"
let value2 = undefined || "default"; // "default"
let value3 = "" || "default"; // "default" (because empty string is falsy)
let value4 = 0 || "default"; // "default" (because 0 is falsy)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;When to Use ??&lt;/strong&gt;&lt;br&gt;
Use ?? instead of || when you only want to fallback for null or undefined while keeping other falsy values (like 0, "", false) intact.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const count = 0;
const result = count ?? 10;  // result is 0, because count is neither null nor undefined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By understanding these differences, you can make better decisions on which operator to use based on your needs! 🚀&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>react</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
