<?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: NisarShaikh</title>
    <description>The latest articles on DEV Community by NisarShaikh (@nisar1406).</description>
    <link>https://dev.to/nisar1406</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%2F546284%2F52d7d65c-5f14-4878-81c9-f1f48f1c92a2.png</url>
      <title>DEV Community: NisarShaikh</title>
      <link>https://dev.to/nisar1406</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nisar1406"/>
    <language>en</language>
    <item>
      <title>If not ternary operator then what?</title>
      <dc:creator>NisarShaikh</dc:creator>
      <pubDate>Fri, 01 Jan 2021 07:46:51 +0000</pubDate>
      <link>https://dev.to/nisar1406/if-not-ternary-operator-then-what-598d</link>
      <guid>https://dev.to/nisar1406/if-not-ternary-operator-then-what-598d</guid>
      <description>&lt;p&gt;Like many languages, JavaScript has the conditional (ternary) operator. What's wonderful about this operator is that it can be nested in expressions and it returns a value. &lt;/p&gt;

&lt;h3&gt;
  
  
  So what is the right way to use it in JavaScript?
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Should we try to avoid it?
&lt;/h3&gt;

&lt;p&gt;While writing code I found something that can replace ternary operator under certain conditions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Traditional use:
&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const foo = a ? a : b;
const bar = c ? true : false;
const baz = c ? flase : true;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  What I found was:
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const foo = a || b;
const bar = !!c;
const baz = !c;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  There is one more, &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; (AND) operation.
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const boo = a `&amp;amp;&amp;amp;` 'Hello';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here the AND operator will short-circuit if the left operand is false, it acts identically to the first part of the ternary operator.&lt;/p&gt;

&lt;p&gt;Do you know more? Please do let me know in the comments.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>codequalit</category>
      <category>syntax</category>
    </item>
  </channel>
</rss>
