<?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: Amani</title>
    <description>The latest articles on DEV Community by Amani (@amanimavu).</description>
    <link>https://dev.to/amanimavu</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%2F1443807%2Fbccd5d52-1e27-4655-ba0f-35040db4030f.png</url>
      <title>DEV Community: Amani</title>
      <link>https://dev.to/amanimavu</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/amanimavu"/>
    <language>en</language>
    <item>
      <title>Vacuous Truth in JS</title>
      <dc:creator>Amani</dc:creator>
      <pubDate>Mon, 05 May 2025 13:06:45 +0000</pubDate>
      <link>https://dev.to/amanimavu/vacuous-truth-in-js-b7o</link>
      <guid>https://dev.to/amanimavu/vacuous-truth-in-js-b7o</guid>
      <description>&lt;p&gt;Just the other day I was testing a permissions function when I came across something very interesting about &lt;strong&gt;Array.prototype.every&lt;/strong&gt;. So, let me give you a little back story. The function I was testing is a a very simple one that check whether a user has permissions required to access given module or action. This function happened to use the JS array method called &lt;strong&gt;every&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;How every works is that it loops through the array and checks whether all items satisfy a provided condition. If it encounters any item that doesn’t it break the loop and returns false, however if all items satisfy the conditions then true is returned. However, there is a peculiar behavior to this method in that if an empty array is used then true is still returned. This is where the concept of vacuous truth comes in&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// typescript
const arr1 = [2, 4, 7, 8, 10]
const arr2 = [2, 4, 6, 8, 10]
const arr3 = []
const checkIfAllAreEven = (items: number[]) =&amp;gt; {
    return items.every((item)=&amp;gt; item % 2 === 0)
}

let allAreEven = checkIfAllAreEven(arr1)
console.log(allAreEven) // logs false
allAreEven = checkIfAllAreEven(arr2)
console.log(allAreEven) // logs true
allAreEven = checkIfAllAreEven(arr3)
console.log(allAreEven) // logs true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The concept of vacuous truth took me back my campus days when I used to study mathematics and getting fascinated with discrete mathematics. I never knew this rabbit hole that I got myself into would re-ignite my interest for discrete mathematics.&lt;/p&gt;

&lt;p&gt;So what are vacuous truths? Vacuous truths are conditional statements with false antecedent. When the antecedent is false, we aren’t able to infer any truth value about the consequent. A statement can also said to be vacuous is the subject of the statement doesn’t exist. So when using every method, the logical statement is all items satisfy a given condition. In the code example above, we want to satisfy that all numbers are even, but there are no numbers for &lt;strong&gt;arr3&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  References
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every" rel="noopener noreferrer"&gt;MDN Web Docs Array.prototype.every() - JavaScript | MDN&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://youtu.be/AQ0f4rsbsrQ?si=Y50HrUFTFnC_B8E8" rel="noopener noreferrer"&gt;Dr. Trefor Bazett Vacuously True Statements&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://youtu.be/_UqrlPD3qHM?si=93LKrdkuqS4vEPMd" rel="noopener noreferrer"&gt;Carneades.org What is Vacuous Truth?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://youtu.be/-M5y2fhQlko?si=XjydMoQvAX46-p3L" rel="noopener noreferrer"&gt;William Spaniel Logic 101 (#13): Why Are "Vacuously True" Statements True?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://youtu.be/GqvX4Fi0jbM?si=f2vScBL0BAfAvxdz" rel="noopener noreferrer"&gt;Dr. Trefor Bazett The Empty Set &amp;amp; Vacuous Truth&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

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