<?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: moadhN</title>
    <description>The latest articles on DEV Community by moadhN (@moadhn).</description>
    <link>https://dev.to/moadhn</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F840263%2F04cd7180-7bfc-4185-a02e-a0bfe1bfc123.png</url>
      <title>DEV Community: moadhN</title>
      <link>https://dev.to/moadhn</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/moadhn"/>
    <language>en</language>
    <item>
      <title>Why is it you can execute a function on the right side of an AND &amp;&amp; operator in JavaScript</title>
      <dc:creator>moadhN</dc:creator>
      <pubDate>Fri, 01 Apr 2022 02:12:52 +0000</pubDate>
      <link>https://dev.to/moadhn/why-is-it-you-can-execute-a-function-on-the-right-side-of-an-and-operator-in-javascript-2633</link>
      <guid>https://dev.to/moadhn/why-is-it-you-can-execute-a-function-on-the-right-side-of-an-and-operator-in-javascript-2633</guid>
      <description>&lt;p&gt;I always assumed that operators like &amp;amp;&amp;amp; and || are for comparing true and false statements on both sides.&lt;/p&gt;

&lt;p&gt;But I'm seeing a pattern in React where, on the right side is a function and the left is a truthy statement that will then allow the right to be executed.&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;truthy statement &amp;amp;&amp;amp; function
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I understand that JavaScript will check this from left to right, so left being true will then allow it to check the right. But my assumption is the right should expect a true or false statement, but in this case it's just a function.&lt;/p&gt;

&lt;p&gt;I'm so used to seeing the &amp;amp;&amp;amp; operator in this context:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (true &amp;amp;&amp;amp; true) {
  // Execute this
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;true &amp;amp;&amp;amp; execute this
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Works at all.&lt;/p&gt;

&lt;p&gt;I guess my assumption is that JavaScript will just evaluate anything next to an operator whether it returns a true or false.&lt;/p&gt;

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