<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Boolean - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Boolean - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Sun, 24 May 2026 16:31:00 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/boolean/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to Convert a Value to a Boolean in JavaScript ]]>
                </title>
                <description>
                    <![CDATA[ A boolean is a primitive value that represents either true or false. In Boolean contexts, JavaScript utilizes type casting to convert values to true/false. There are implicit and explicit methods to convert values into their boolean counterparts. Thi... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-convert-value-to-boolean-javascript/</link>
                <guid isPermaLink="false">66bc4cabe35f27b3539506d7</guid>
                
                    <category>
                        <![CDATA[ beginner ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Boolean ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Natalie Pina ]]>
                </dc:creator>
                <pubDate>Fri, 20 May 2022 18:06:38 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/05/Fashion-Sale--Banner--Landscape--.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>A boolean is a <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Glossary/Primitive">primitive value</a> that represents either true or false. In Boolean contexts, JavaScript utilizes <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Glossary/Type_Conversion">type casting</a> to convert values to true/false. There are implicit and explicit methods to convert values into their boolean counterparts.</p>
<p>This article provides an overview of truthy and falsy values and how to convert values into booleans in JavaScript.</p>
<h3 id="heading-javascript-truthy-and-falsy-values-cheatsheet">JavaScript Truthy and Falsy Values Cheatsheet</h3>
<pre><code><span class="hljs-built_in">Boolean</span>(<span class="hljs-literal">false</span>);         <span class="hljs-comment">// false</span>
<span class="hljs-built_in">Boolean</span>(<span class="hljs-literal">undefined</span>);     <span class="hljs-comment">// false</span>
<span class="hljs-built_in">Boolean</span>(<span class="hljs-literal">null</span>);          <span class="hljs-comment">// false</span>
<span class="hljs-built_in">Boolean</span>(<span class="hljs-string">''</span>);            <span class="hljs-comment">// false</span>
<span class="hljs-built_in">Boolean</span>(<span class="hljs-literal">NaN</span>);           <span class="hljs-comment">// false</span>
<span class="hljs-built_in">Boolean</span>(<span class="hljs-number">0</span>);             <span class="hljs-comment">// false</span>
<span class="hljs-built_in">Boolean</span>(<span class="hljs-number">-0</span>);            <span class="hljs-comment">// false</span>
<span class="hljs-built_in">Boolean</span>(<span class="hljs-number">0n</span>);            <span class="hljs-comment">// false</span>

<span class="hljs-built_in">Boolean</span>(<span class="hljs-literal">true</span>);          <span class="hljs-comment">// true</span>
<span class="hljs-built_in">Boolean</span>(<span class="hljs-string">'hi'</span>);          <span class="hljs-comment">// true</span>
<span class="hljs-built_in">Boolean</span>(<span class="hljs-number">1</span>);             <span class="hljs-comment">// true</span>
<span class="hljs-built_in">Boolean</span>([]);            <span class="hljs-comment">// true</span>
<span class="hljs-built_in">Boolean</span>([<span class="hljs-number">0</span>]);           <span class="hljs-comment">// true</span>
<span class="hljs-built_in">Boolean</span>([<span class="hljs-number">1</span>]);           <span class="hljs-comment">// true</span>
<span class="hljs-built_in">Boolean</span>({});            <span class="hljs-comment">// true</span>
<span class="hljs-built_in">Boolean</span>({ <span class="hljs-attr">a</span>: <span class="hljs-number">1</span> });      <span class="hljs-comment">// true</span>
</code></pre><p>It's best to start by first understanding which values are interpreted as truthy or falsy by JavaScript. It's also important to understand <a target="_blank" href="https://betterprogramming.pub/implicit-and-explicit-coercion-in-javascript-b23d0cb1a750">implicit coercion</a> compared to <a target="_blank" href="https://www.bookstack.cn/read/TypesGrammar/spilt.3.ch4.md#Explicitly:%20*%20%E2%80%94%3E%20Boolean">explicit coercion</a>. </p>
<p>Implicit coercion is initiated by the JavaScript engine and happens automatically. Explicit coercion is performed by manually converting values, and JavaScript provides built in methods to handle this.</p>
<h3 id="heading-the-operator">The <code>!!</code> Operator</h3>
<pre><code class="lang-javascript">!!value
</code></pre>
<p>You may already be familiar with <code>!</code> as the logical NOT operator. When using two in succession (<code>!!</code>), the first <code>!</code> coerces the value to a boolean and inverts it. For example <code>!true</code> would result in false. The second <code>!</code> reverses the previous inverted value, resulting in the true boolean value.</p>
<p>This is generally a preferred method, as it has <a target="_blank" href="https://www.measurethat.net/Benchmarks/Show/11127/0/boolean-vs">better performance</a>. A potential con to this method is a loss in readability, mainly if other developers are unfamiliar with how this operator works.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> value = <span class="hljs-string">"truthy string"</span>
!!value <span class="hljs-comment">// true</span>
</code></pre>
<p>Here is an example breaking this down into steps:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> value = <span class="hljs-string">"truthy string"</span>;

!value; <span class="hljs-comment">// false</span>
!!value; <span class="hljs-comment">// true</span>
</code></pre>
<p>Below is a list of example output with the <code>!!</code> operator.</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// Falsy Values</span>

!!<span class="hljs-string">''</span> <span class="hljs-comment">// false</span>
!!<span class="hljs-literal">false</span> <span class="hljs-comment">// false</span>
!!<span class="hljs-literal">null</span> <span class="hljs-comment">// false</span>
!!<span class="hljs-literal">undefined</span> <span class="hljs-comment">// false</span>
!!<span class="hljs-number">0</span> <span class="hljs-comment">// false</span>
!!<span class="hljs-literal">NaN</span> <span class="hljs-comment">// false</span>


<span class="hljs-comment">// Truthy Values</span>

!![] <span class="hljs-comment">// true</span>
!!<span class="hljs-string">"false"</span> <span class="hljs-comment">// true</span>
!!<span class="hljs-literal">true</span> <span class="hljs-comment">// true</span>
!!<span class="hljs-number">1</span> <span class="hljs-comment">// true</span>
!!{} <span class="hljs-comment">// true</span>
</code></pre>
<h3 id="heading-the-boolean-function">The <code>Boolean()</code> Function</h3>
<pre><code class="lang-javascript"><span class="hljs-built_in">Boolean</span>(value)
</code></pre>
<p><code>Boolean()</code> is a global function that converts the value it's passed into a boolean.   </p>
<p>You shouldn't use this with the new keyword (<code>new Boolean</code>) as this creates an instance of a Boolean that has a type of object. Below is an example of the correct use of this function.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> value = <span class="hljs-string">"truthy string"</span>
<span class="hljs-built_in">Boolean</span>(value) <span class="hljs-comment">// true</span>
</code></pre>
<h2 id="heading-tldr">TL;DR</h2>
<p>There are two methods to cast a value to a boolean in JavaScript.</p>
<h3 id="heading-1">1. <code>!!</code></h3>
<pre><code class="lang-javascript">!!value
</code></pre>
<h3 id="heading-2-boolean">2. <code>Boolean()</code></h3>
<pre><code><span class="hljs-built_in">Boolean</span>(value)
</code></pre><pre><code class="lang-javascript"><span class="hljs-keyword">const</span> finalThoughts = <span class="hljs-string">"I really enjoyed writing this article. Thanks for reading!"</span>

!!finalThoughts <span class="hljs-comment">// true</span>
<span class="hljs-built_in">Boolean</span>(finalThoughts) <span class="hljs-comment">// true</span>
</code></pre>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Boolean Definition ]]>
                </title>
                <description>
                    <![CDATA[ In computer science, a boolean refers to a value that is either true or false. Boolean gets its name from the English mathematician, George Boole. Boole created a new branch of algebra, now known as Boolean Algebra, where the value of true is 1 and t... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/boolean-definition/</link>
                <guid isPermaLink="false">66c3462c8ced2460cf9e9b50</guid>
                
                    <category>
                        <![CDATA[ Boolean ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Tech Terms ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Fri, 19 Mar 2021 06:43:00 +0000</pubDate>
                <media:content url="https://cdn-media-2.freecodecamp.org/w1280/605d74a79618b008528a7978.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>In computer science, a boolean refers to a value that is either true or false.</p>
<p>Boolean gets its name from the English mathematician, George Boole.</p>
<p>Boole created a new branch of algebra, now known as Boolean Algebra, where the value of true is 1 and the value of false is 0. In Boolean Algebra, there are three main logical operations: <strong>AND</strong>, <strong>OR</strong>, and <strong>NOT</strong>.</p>
<p>Boolean Algebra laid the foundation for the information age and computer science. All computers function using the basic principles of Boolean Algebra, where 1, or true, is on, and 0, or false, is off.</p>
<p>Because of this, many programming languages include boolean data types and operators.</p>
<p>For example, in JavaScript, it's common to see the boolean data types <code>true</code> and <code>false</code>:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> isCat = <span class="hljs-literal">true</span>;
</code></pre>
<p>JavaScript also has logical operators for <strong>AND</strong>:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> isCat = <span class="hljs-literal">true</span>;
<span class="hljs-keyword">const</span> isCute = <span class="hljs-literal">true</span>;

<span class="hljs-keyword">if</span> (isCat &amp;&amp; isCute) { <span class="hljs-comment">// isCat AND isCute are both true</span>
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"There's a cute cat :D"</span>); <span class="hljs-comment">// logs "There's a cute cat :D" to the console</span>
}
</code></pre>
<p><strong>OR</strong>:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> isCat = <span class="hljs-literal">true</span>;
<span class="hljs-keyword">const</span> isFluffy = <span class="hljs-literal">false</span>;

<span class="hljs-keyword">if</span> (isCat || isFluffy) { <span class="hljs-comment">// either isCat OR isFluffy are true</span>
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"There's an animal that might be a cat, fluffly, or both"</span>); <span class="hljs-comment">// logs "There's an animal that might be a cat, fluffly, or both" to the console</span>
}
</code></pre>
<p>And <strong>NOT</strong>:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> isCat = <span class="hljs-literal">true</span>;
<span class="hljs-keyword">const</span> isFluffy = <span class="hljs-literal">false</span>;

<span class="hljs-keyword">if</span> (!isFluffy) { <span class="hljs-comment">// isFluffy is false, or NOT true</span>
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Whatever this animal is, it's not fluffy"</span>); <span class="hljs-comment">// logs "Whatever this animal is, it's not fluffy" to the console</span>
}
</code></pre>
<p>Also, like many other programming languages, JavaScript has other operators that return a boolean value:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> catName = <span class="hljs-string">'Boomer'</span>;

<span class="hljs-keyword">if</span> (catName === <span class="hljs-string">'Boomer'</span>) { <span class="hljs-comment">// evaluates to true</span>
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'BOOMER LIVES!'</span>); <span class="hljs-comment">// logs 'BOOMER LIVES!' to the console</span>
}
</code></pre>
<h2 id="heading-related-tech-terms">Related Tech Terms:</h2>
<ul>
<li><a target="_blank" href="https://www.freecodecamp.org/news/binary-definition/">Binary Definition</a></li>
<li><a target="_blank" href="https://www.freecodecamp.org/news/bit-definition/">Bit Definition</a></li>
</ul>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Boolean Algebra Truth Table Tutorial – XOR, NOR, and Logic Symbols Explained ]]>
                </title>
                <description>
                    <![CDATA[ By Aditya We all love computers. They can do so many amazing things. Within a couple of decades computers have completely revolutionized almost all the aspects of human life.  They can do tasks of varying degrees of sophistication, all by just flippi... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/boolean-algebra/</link>
                <guid isPermaLink="false">66d45dd5d14641365a050898</guid>
                
                    <category>
                        <![CDATA[ Advanced Mathematics ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Boolean ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Math ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 04 May 2020 21:31:31 +0000</pubDate>
                <media:content url="https://cdn-media-2.freecodecamp.org/w1280/5f9c9b45740569d1a4ca2aca.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Aditya</p>
<p>We all love computers. They can do so many amazing things. Within a couple of decades computers have completely revolutionized almost all the aspects of human life. </p>
<p>They can do tasks of varying degrees of sophistication, all by just flipping zeros and ones. It is remarkable to see how such a simple action can lead to so much complexity.</p>
<p>But I'm sure you all know that such complexity cannot be achieved (practically) by just randomly flipping the numbers. There is indeed some reasoning behind it. There are rules that govern the way this should be done. In this article we will discuss those rules and we will see how they govern the way computers "think".</p>
<h2 id="heading-what-is-boolean-algebra">What is Boolean Algebra?</h2>
<p>The rules I mentioned above are described by a field of Mathematics called Boolean Algebra. </p>
<p>In his 1854 book, British Mathematician George Boole proposed a systematic set of rules for manipulation of Truth Values. These rules gave a mathematical foundation for dealing with logical propositions. These sets of foundations led to the development of Boolean Algebra. </p>
<p>To best understand Boolean Algebra, we first have to understand the similarities and differences between Boolean Algebra and other forms of Algebra. </p>
<p>Algebra, in general, deals with the study of mathematical symbols and the operations that can be performed on these symbols.</p>
<p>These symbols do not have a meaning of their own. They represent some other quantity. It is this quantity that gives some value to these symbols and it is this quantity on which the operations are actually being performed. </p>
<p>Boolean Algebra also deals with symbols and the rules that govern the operations on these symbols but the difference lies in <em>what these symbols represent</em>. </p>
<p>In case of ordinary Algebra, the symbols represent the Real numbers whereas in Boolean Algebra they represent the Truth values.</p>
<p>The image below shows the entire set of Real numbers. The set of Real numbers includes Natural numbers(1, 2, 3, 4....), Whole numbers (all the Natural numbers and 0), Integers (.....-2, -1, 0, 1, 2, 3 ...) and so on. Ordinary Algebra deals with this entire set of numbers. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/08/numbersys.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>The Truth values, in comparison, consist of a set of only two values: False and True. Here, I would like to point out the fact that we can use any other symbol to represent these values. </p>
<p>For example in Computer Science we mostly represent these values using 0 and 1. 0 is used for False and 1 for True. </p>
<p>You can also do it in more fancy ways by representing truth values with some other symbols such as Cats and Dogs or Bananas and Oranges. </p>
<p>The point here is that the internal meaning of these symbols will remain the same irrespective of the symbol you use. But make sure that you don't change the symbols while performing the operations. </p>
<p>Now the question is that if (True and False), (0 and 1) are just the representations, then what is it that they are trying to represent? </p>
<p>The underlying meaning behind truth values comes from field of Logic where truth values are used to tell if a proposition is "True" or "False". Here the truth values represent the <em>relation of a proposition to truth,</em> that is, whether  the proposition is true or false.</p>
<p>A proposition is just a statement like "All cats are cute."</p>
<p>If the above proposition is true then we assign it the truth value of "True" or "1" otherwise we assign it "False" or "0".</p>
<p>In Digital Electronics, truth values are used to represent the "On" and "Off" states of electronic circuits. We will discuss more about that later in this article. </p>
<h2 id="heading-boolean-operations-and-truth-tables">Boolean Operations and Truth Tables</h2>
<p>Just like Ordinary Algebra, Boolean Algebra also has operations which can be applied on the values to get some results. Although these operations are not similar to ones in ordinary algebra because, as we discussed earlier, Boolean algebra works on Truth values rather than Real Numbers.</p>
<h3 id="heading-boolean-algebra-has-three-basic-operations">Boolean Algebra has three basic operations.</h3>
<p><strong>OR</strong>: Also known as <em>Disjunction</em>. This operation is performed on two Boolean variables. The output of the OR operation will be 0 when both of the operands are 0, otherwise it will be 1. </p>
<p>To get a clearer picture of what this operation does we can visualize it with the help of a <strong>Truth Table</strong> below.</p>
<pre><code>Truth tables give us an insightful representation <span class="hljs-keyword">of</span> what the <span class="hljs-built_in">Boolean</span> operations <span class="hljs-keyword">do</span> and they also act <span class="hljs-keyword">as</span> a handy tool <span class="hljs-keyword">for</span> performing <span class="hljs-built_in">Boolean</span> operations.

        OR Operation

Variable<span class="hljs-number">-1</span>    Variable<span class="hljs-number">-2</span>    Output
  <span class="hljs-number">0</span>        <span class="hljs-number">0</span>        <span class="hljs-number">0</span>
  <span class="hljs-number">0</span>        <span class="hljs-number">1</span>        <span class="hljs-number">1</span>
  <span class="hljs-number">1</span>        <span class="hljs-number">0</span>        <span class="hljs-number">1</span>
  <span class="hljs-number">1</span>        <span class="hljs-number">1</span>        <span class="hljs-number">1</span>
</code></pre><p><strong>AND</strong>: Also known as <em>Conjunction</em>. This operation is performed on two Boolean variables. The output of AND operations will be 1 when both operands are 1, otherwise it will be 0. The truth table representation is as follows.</p>
<pre><code>        AND Operation

Variable<span class="hljs-number">-1</span>    Variable<span class="hljs-number">-2</span>    Output
  <span class="hljs-number">0</span>        <span class="hljs-number">0</span>        <span class="hljs-number">0</span>
  <span class="hljs-number">0</span>        <span class="hljs-number">1</span>        <span class="hljs-number">0</span>
  <span class="hljs-number">1</span>        <span class="hljs-number">0</span>        <span class="hljs-number">0</span>
  <span class="hljs-number">1</span>        <span class="hljs-number">1</span>        <span class="hljs-number">1</span>
</code></pre><p><strong>NOT</strong>: Also known as <em>Negation</em>. This operation is performed only on one variable. If the value of the variable is 1 then this operation simply converts it into 0 and if the value of the variable is 0, then it converts it into 1.</p>
<pre><code>    Not Operation

Variable<span class="hljs-number">-1</span>    Output
  <span class="hljs-number">0</span>        <span class="hljs-number">1</span>    
  <span class="hljs-number">1</span>        <span class="hljs-number">0</span>
</code></pre><h2 id="heading-boolean-algebra-and-digital-circuits">Boolean Algebra and Digital Circuits</h2>
<p>After its initial development, Boolean Algebra, for a very long time, remained one of those concepts in Mathematics which did not have any significant practical applications. </p>
<p>In the 1930s, Claude Shannon, an American Mathematician, realised that Boolean Algebra could be used in circuits where the binary variables could represent the "low" and "high" voltage signals or "on" and "off" states.</p>
<p>This simple idea of making circuits with the help of Boolean Algebra led to the development of Digital Electronics which contributed heavily in the development of circuits for computers. </p>
<p>Digital Circuits implement Boolean Algebra with the help of Logic Gates. Logic Gates are the circuits which represent a boolean operation. For example an OR gate will represent an OR operation. The same goes for NOT and AND gates as well. </p>
<p>Alongside the basic logic gates we also have logic gates that can be created using the combination of the basic logic gates. </p>
<p><strong>NAND</strong>: NAND gate is formed by a combination of the NOT and AND gates. NAND gate gives an output of 0 if both inputs are 1, otherwise 1. </p>
<p>NAND gate holds the property of Functional Completeness, which means that any boolean function can be implemented just by using a combination of NAND gates only.</p>
<pre><code>        NAND Gate

Variable<span class="hljs-number">-1</span>    Variable<span class="hljs-number">-2</span>    Output
  <span class="hljs-number">0</span>        <span class="hljs-number">0</span>        <span class="hljs-number">1</span>
  <span class="hljs-number">0</span>        <span class="hljs-number">1</span>        <span class="hljs-number">1</span>
  <span class="hljs-number">1</span>        <span class="hljs-number">0</span>        <span class="hljs-number">1</span>
  <span class="hljs-number">1</span>        <span class="hljs-number">1</span>        <span class="hljs-number">0</span>
</code></pre><p><strong>NOR</strong>: NOR gate is formed by a combination of NOT and OR gates. NOR gate gives an output of 1 if both inputs are 0, otherwise 0. </p>
<p>NOR gate, just like NAND gate, holds the property of Functional Completeness, which means that any boolean function can be implemented just by using a combination of NOR gates only. </p>
<pre><code>        NOR Gate

Variable<span class="hljs-number">-1</span>    Variable<span class="hljs-number">-2</span>    Output
  <span class="hljs-number">0</span>        <span class="hljs-number">0</span>        <span class="hljs-number">1</span>
  <span class="hljs-number">0</span>        <span class="hljs-number">1</span>        <span class="hljs-number">0</span>
  <span class="hljs-number">1</span>        <span class="hljs-number">0</span>        <span class="hljs-number">0</span>
  <span class="hljs-number">1</span>        <span class="hljs-number">1</span>        <span class="hljs-number">0</span>
</code></pre><p>Most digital circuits are built using NAND or NOR gates because of their functional completeness property and also because they are easy to fabricate. </p>
<p>Other than the above mentioned gates we also have some special kind of gates which serve some specific purpose. These are as follows:</p>
<p><strong>XOR</strong>: XOR gate or Exclusive-OR gate is a special type of logic gate which gives 0 as output if both of the inputs are either 0 or 1, otherwise it gives 1. </p>
<pre><code>        XOR Gate

Variable<span class="hljs-number">-1</span>    Variable<span class="hljs-number">-2</span>    Output
  <span class="hljs-number">0</span>        <span class="hljs-number">0</span>        <span class="hljs-number">0</span>
  <span class="hljs-number">0</span>        <span class="hljs-number">1</span>        <span class="hljs-number">1</span>
  <span class="hljs-number">1</span>        <span class="hljs-number">0</span>        <span class="hljs-number">1</span>
  <span class="hljs-number">1</span>        <span class="hljs-number">1</span>        <span class="hljs-number">0</span>
</code></pre><p><strong>XNOR</strong>: XNOR gate or Exclusive-NOR gate is a special type of logic gate which gives 1 as output when both the inputs are either 0 or 1, otherwise it gives 0.</p>
<pre><code>        XNOR Gate

Variable<span class="hljs-number">-1</span>    Variable<span class="hljs-number">-2</span>    Output
  <span class="hljs-number">0</span>        <span class="hljs-number">0</span>        <span class="hljs-number">1</span>
  <span class="hljs-number">0</span>        <span class="hljs-number">1</span>        <span class="hljs-number">0</span>
  <span class="hljs-number">1</span>        <span class="hljs-number">0</span>        <span class="hljs-number">0</span>
  <span class="hljs-number">1</span>        <span class="hljs-number">1</span>        <span class="hljs-number">1</span>
</code></pre><h2 id="heading-conclusion">Conclusion</h2>
<p>So, with all that we can now conclude our discussion on Boolean Algebra here. I hope by now you have a decent picture of what Boolean Algebra is all about. </p>
<p>This is definitely not all you need to know about Boolean Algebra. Boolean Algebra has a lot of concepts and details that we were not able to discuss in this article. </p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Data Types in Ruby - True, False, and Nil Explained with Examples ]]>
                </title>
                <description>
                    <![CDATA[ true, false, and nil are special built-in data types in Ruby. Each of these keywords evaluates to an object that is the sole instance of its respective class. true.class  => TrueClass false.class  => FalseClass nil.class  => NilClass true and false ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/data-types-in-ruby-true-false-and-nil-explained-with-examples/</link>
                <guid isPermaLink="false">66c348ab3a31d2480bb383aa</guid>
                
                    <category>
                        <![CDATA[ Boolean ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Ruby ]]>
                    </category>
                
                    <category>
                        <![CDATA[ toothbrush ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Sat, 01 Feb 2020 00:00:00 +0000</pubDate>
                <media:content url="https://cdn-media-2.freecodecamp.org/w1280/5f9c9cf8740569d1a4ca352a.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p><code>true</code>, <code>false</code>, and <code>nil</code> are special built-in data types in Ruby. Each of these keywords evaluates to an object that is the sole instance of its respective class.</p>
<pre><code class="lang-ruby"><span class="hljs-literal">true</span>.<span class="hljs-keyword">class</span>
 =&gt; TrueClass
<span class="hljs-literal">false</span>.<span class="hljs-keyword">class</span>
 =&gt; FalseClass
<span class="hljs-literal">nil</span>.<span class="hljs-keyword">class</span>
 =&gt; NilClass
</code></pre>
<p><code>true</code> and <code>false</code> are Ruby’s native boolean values. A boolean value is a value that can only be one of two possible values: true or not true. The object <code>true</code> represents truth, while <code>false</code> represents the opposite. You can assign variables to <code>true</code> / <code>false</code>, pass them to methods, and generally use them as you would other objects (such as numbers, Strings, Arrays, Hashes).</p>
<p><code>nil</code> is a special value that indicates the absence of a value – it is Ruby’s way of referring to “nothing”. An example of when you will encounter the <code>nil</code> object is when you ask for something that doesn’t exist or cannot be found:</p>
<pre><code class="lang-ruby">hats = [<span class="hljs-string">"beret"</span>, <span class="hljs-string">"sombrero"</span>, <span class="hljs-string">"beanie"</span>, <span class="hljs-string">"fez"</span>, <span class="hljs-string">"flatcap"</span>]

hats[<span class="hljs-number">0</span>]
 =&gt; <span class="hljs-string">"beret"</span> <span class="hljs-comment"># the hat at index 0</span>
hats[<span class="hljs-number">2</span>]
 =&gt; <span class="hljs-string">"beanie"</span> <span class="hljs-comment"># the hat at index 2</span>
hats[<span class="hljs-number">4</span>]
 =&gt; <span class="hljs-string">"flatcap"</span> <span class="hljs-comment"># the hat at index 4</span>
hats[<span class="hljs-number">5</span>]
 =&gt; nil <span class="hljs-comment"># there is no hat at index 5, index 5 holds nothing (nil)</span>
</code></pre>
<p>Zero is not nothing (it’s a number, which is something). Likewise, empty strings, arrays, and hashes are not nothing (they are objects, which happen to be empty). You can call the method <code>nil?</code> to check whether an object is nil.</p>
<pre><code class="lang-ruby"><span class="hljs-number">0</span>.<span class="hljs-literal">nil</span>?
 =&gt; <span class="hljs-literal">false</span>
<span class="hljs-string">""</span>.<span class="hljs-literal">nil</span>?
 =&gt; <span class="hljs-literal">false</span>
[].<span class="hljs-literal">nil</span>?
 =&gt; <span class="hljs-literal">false</span>
{}.<span class="hljs-literal">nil</span>?
 =&gt; <span class="hljs-literal">false</span>
<span class="hljs-literal">nil</span>.<span class="hljs-literal">nil</span>?
 =&gt; <span class="hljs-literal">true</span>
 <span class="hljs-comment"># from the example above</span>
hats[<span class="hljs-number">5</span>].<span class="hljs-literal">nil</span>?
 =&gt; <span class="hljs-literal">true</span>
</code></pre>
<p>Every object in Ruby has a boolean value, meaning it is considered either true or false in a boolean context. Those considered true in this context are “truthy” and those considered false are “falsey.” In Ruby, <em>only</em> <code>false</code> and <code>nil</code> are “falsey,” everything else is “truthy.”</p>
<h2 id="heading-more-information">More Information:</h2>
<ul>
<li><a target="_blank" href="https://www.freecodecamp.org/news/learning-ruby-from-zero-to-hero-90ad4eecc82d/">Learning Ruby: From Zero to Hero</a></li>
<li><a target="_blank" href="https://www.freecodecamp.org/news/idiomatic-ruby-writing-beautiful-code-6845c830c664/">Idiomatic Ruby: writing beautiful code</a></li>
<li><a target="_blank" href="https://www.freecodecamp.org/news/export-a-database-table-to-csv-using-a-simple-ruby-script-2/">How to Export a Database Table to CSV Using a Simple Ruby Script</a></li>
</ul>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ JavaScript booleans explained by going to court ]]>
                </title>
                <description>
                    <![CDATA[ By Kevin Kononenko If you have ever watched a TV show about court (or been to court), then you can understand booleans in JavaScript. You might think that booleans are the most straightforward topic that you could ask for in JavaScript. After all, si... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/javascript-booleans-explained-by-going-to-court-a0ca1149a0dc/</link>
                <guid isPermaLink="false">66c358d139357f94469765c6</guid>
                
                    <category>
                        <![CDATA[ Boolean ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ technology ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 18 Jun 2018 04:04:31 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*-ZzuerbatF4F0uu9qCvHaA.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Kevin Kononenko</p>
<p>If you have ever watched a TV show about court (or been to court), then you can understand booleans in JavaScript.</p>
<p>You might think that booleans are the most straightforward topic that you could ask for in JavaScript.</p>
<p>After all, since a variable can be any of the following:</p>
<ul>
<li>number</li>
<li>string</li>
<li>array</li>
<li>object</li>
<li>boolean</li>
</ul>
<p>…boolean seems to be the easiest.</p>
<pre><code><span class="hljs-keyword">let</span> bool = <span class="hljs-literal">true</span>;
</code></pre><pre><code><span class="hljs-keyword">let</span> bool= <span class="hljs-literal">false</span>;
</code></pre><p>The only two options for a boolean are <code>true</code> or <code>false</code>. And they are used in <code>if()</code> statements to decide which statement should be executed.</p>
<pre><code><span class="hljs-keyword">if</span>(<span class="hljs-literal">true</span>){
</code></pre><pre><code>}
</code></pre><pre><code><span class="hljs-keyword">else</span>{
</code></pre><pre><code><span class="hljs-comment">// if value is false, this block runs</span>
</code></pre><pre><code>}
</code></pre><p>But here’s the thing. Within <code>if()</code> statements, other variable values can <strong>evaluate</strong> to true or false. In other words, once the value is used in the <code>if()</code> statement, JavaScript will evaluate whether it is <code>true</code> or <code>false</code>.</p>
<p>For example, do you know if the value 0 is <code>true</code> or <code>false</code>?</p>
<p>This is not a philosophy question. JavaScript has an answer.</p>
<p>Anyways, this happens because JavaScript is a <strong>weakly typed</strong> language. This means that in the context of an <code>if()</code> statement, it will convert other variable values to <code>true</code> or <code>false</code> in order to run the code. This is known as determining the “truthiness” of a value.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0*JYzIah834O2zHY4K" alt="Image" width="800" height="302" loading="lazy"></p>
<p>Many other languages are <strong>strongly typed</strong>, so they will not convert values into true or false.</p>
<p>This may seem a little crazy, but it is actually pretty similar to the way that a judge in the United States determines whether an accused person is innocent or guilty. So, I can explain the way that “truthiness” and <code>true</code>/<code>false</code> works in JavaScript through legal rules that you have seen in “Law and Order” or any other court-based procedural dramas on TV.</p>
<p>For the purposes of this tutorial, imagine that you are a district attorney that is trying to prosecute a person who is accused of stealing a car.</p>
<p>And, you will need to understand the <a target="_blank" href="https://blog.codeanalogies.com/2017/12/20/a-visual-guide-to-understanding-the-sign-in-javascript/">basics of variables in JavaScript</a> to use this tutorial. Let’s get into it!</p>
<h3 id="heading-what-is-truthiness-in-javascript">What is “truthiness” in JavaScript?</h3>
<p>In the United States, the criminal law system states that an accused person is “innocent until proven guilty”. That means that the burden lies on the prosecutor (you, in this case) to provide enough evidence to disprove the default assumption that the accused person is innocent.</p>
<p>In fact, the standard of evidence is “<a target="_blank" href="https://en.wikipedia.org/wiki/Reasonable_doubt">beyond a reasonable doubt.</a>” This is consistent across many countries in the world.</p>
<p>When we use <code>if()</code> statements, we are not always going to be able to plug in a variable with a value of <code>true</code> or <code>false</code>. Many times, we must plug in a statement that will be evaluated by JavaScript <strong>as</strong> <code>true</code> or <code>false</code>.</p>
<p>This is similar to the legal system! Although it is <strong>possible</strong> that there will be one piece of evidence that makes the “guilty” or “not guilty” verdict obvious, it is also likely that a judge or jury will need to evaluate multiple pieces of evidence and make a decision.</p>
<p>Let’s start with the basics. A <code>true</code> statement is evidence that will lead to the conviction of the accused. A <code>false</code> statement is evidence that will let them walk free. Let’s create a variable called <code>evidence</code> and set it to <code>true</code>.</p>
<pre><code><span class="hljs-keyword">let</span> evidence = <span class="hljs-literal">true</span>;
</code></pre><pre><code><span class="hljs-keyword">if</span> (evidence){
</code></pre><pre><code>  convict();
</code></pre><pre><code>}
</code></pre><pre><code><span class="hljs-keyword">else</span>{
</code></pre><pre><code>  release();
</code></pre><pre><code>}
</code></pre><p><code>convict()</code> and <code>release()</code> are made-up functions. In this case, since evidence is set to <code>true</code>, the judge would convict the car thief. Here’s an interactive diagram of this scenario.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*hQ4EcsTZPmWWNOXLvxRThQ.jpeg" alt="Image" width="800" height="283" loading="lazy"></p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*zNtmdN3AjQ4Tpcl_Xa_oKA.jpeg" alt="Image" width="800" height="283" loading="lazy"></p>
<p>The robber kinda looks like Edward Norton from “The Italian Job”, eh?</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0*FRlRPnEU3_Pu7fYK" alt="Image" width="780" height="437" loading="lazy"></p>
<p>Anyways, in real life, it is never this straightforward. Let’s say that you have a killer piece of evidence — fingerprints from the car door. You present that to the judge.</p>
<pre><code><span class="hljs-keyword">let</span> evidence = <span class="hljs-string">"fingerprints"</span>;
</code></pre><pre><code><span class="hljs-keyword">if</span> (evidence){
</code></pre><pre><code>  convict();
</code></pre><pre><code>}
</code></pre><pre><code><span class="hljs-keyword">else</span>{
</code></pre><pre><code>  release();
</code></pre><pre><code>}
</code></pre><p>Aha! We only changed the first line, where we declared the variable evidence. And it is now a string rather than a boolean. But guess what? Due to <strong>type coercion</strong>, JavaScript will evaluate the string as <code>true</code>. Since there is no condition within the <code>if()</code> statement, all strings are <code>true</code>. We would run the <code>convict()</code> function!</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0*3f8jEtYDOMaiVPeX" alt="Image" width="800" height="271" loading="lazy"></p>
<h3 id="heading-examples-of-truthiness">Examples of truthiness</h3>
<p>Let’s imagine that instead, the evidence variable is set to <code>0</code>. We run the same <code>if()</code> statement again.</p>
<pre><code><span class="hljs-keyword">let</span> evidence = <span class="hljs-number">0</span>;
</code></pre><pre><code><span class="hljs-keyword">if</span> (evidence){
</code></pre><pre><code>  convict();
</code></pre><pre><code>}
</code></pre><pre><code><span class="hljs-keyword">else</span>{
</code></pre><pre><code>  release();
</code></pre><pre><code>}
</code></pre><p>In this case, the statement would actually evaluate to <code>false</code>, and our accused car thief would be released.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0*x6feidPaPL5Uga82" alt="Image" width="800" height="283" loading="lazy"></p>
<p>This is why it is called “truthiness” — because JavaScript is evaluating whether the condition is <code>true</code> or <code>false</code>.</p>
<p>Since the variable is set to <code>0</code>, it’s kind of like if you were asked to present evidence against the thief, and you said… nothing.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0*vDx4QLx1Hfwa6e07" alt="Image" width="800" height="309" loading="lazy"></p>
<p>Obviously the judge is going to determine you don’t have enough evidence, and set the person free! The same would happen if evidence was set to an empty string <code>```. You still aren’t offering anything, so your statement is evaluated as</code>false`<em>.</em></p>
<pre><code><span class="hljs-keyword">let</span> evidence = <span class="hljs-string">''</span>;
</code></pre><p>Here’s one more test to see if you understand <code>true</code> versus <code>false</code>. What if the variable has not yet been initialized to a value?</p>
<pre><code><span class="hljs-keyword">let</span> evidence;
</code></pre><pre><code><span class="hljs-keyword">if</span> (evidence){
</code></pre><pre><code>  convict();
</code></pre><pre><code>}
</code></pre><pre><code><span class="hljs-keyword">else</span>{
</code></pre><pre><code>  release();
</code></pre><pre><code>}
</code></pre><p>This is a pretty common one, because web developers will have another statement in their script that gives a value to the <code>evidence</code> variable. And, just like the two examples above, JavaScript will evaluate this variable as <code>false</code> if it does not have any value.</p>
<p>This is a great example of “innocent until proven guilty”. The variable has not yet been assigned a value, so there is no way JavaScript could call it <code>true</code>.</p>
<h3 id="heading-using-dom-elements-in-if-statements">Using DOM Elements in if() statements</h3>
<p>So we have covered values of variables that are “falsy”. But what about elements from the DOM?</p>
<p><strong>Note</strong>: if you need a refresher, check out my <a target="_blank" href="https://blog.codeanalogies.com/2018/01/06/traversing-the-dom-visual-explanation/">guide to DOM elements here</a>.</p>
<p>In other words, what happens when we use a DOM element to determine which branch of an <code>if/else</code> statement to run? If you use jQuery or React (or Angular, and so forth), you probably manipulate the DOM in order to create a more dynamic interface.</p>
<p>In our courtroom example, let’s say that you swear that the lockpick the thief used is located in a trashcan near the crime scene. In HTML terms, you are saying that there is a div with ID <code>lockpick</code> somewhere in the DOM. How might the judge validate your claim?</p>
<pre><code><span class="hljs-keyword">if</span>(<span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'lockpick'</span>)){
</code></pre><pre><code>  convict()
</code></pre><pre><code>}
</code></pre><pre><code><span class="hljs-keyword">else</span>{
</code></pre><pre><code>  release()
</code></pre><pre><code>}
</code></pre><p>Here’s an interactive image of that scenario.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*p37rdMZPQYElpR9ZZCITcQ.jpeg" alt="Image" width="800" height="412" loading="lazy"></p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*jcorLVV6rRXqiHk_XnBKdQ.jpeg" alt="Image" width="800" height="412" loading="lazy"></p>
<p>“Truthiness” here means that JavaScript will inspect the DOM, and only return <code>true</code> if it finds an element with ID <code>lockpick</code>. It’s kind of like a judge determining if the evidence that you present is real and authentic. In this case, it is, so the first block of code will run, and the person will be convicted.</p>
<p>This is super useful! We have now extended the concept of <code>true</code> so that it includes whether an element exists or not. This logic also applies to objects and arrays. You can check whether an element with a specific class exists, whether a certain element has children, you get the idea.</p>
<h3 id="heading-more-variations-of-if-statements">More variations of if() statements</h3>
<p>When you bring an accused person to court, they may still be convicted of a lesser crime. If you don’t have enough evidence for the main charge, they can still be convicted of a lower charges.</p>
<p>In the example of car theft, there is a breaking and entering crime, and then theft is possible if the accused person has already broken into the car.</p>
<p>We can combine <code>if()</code>, <code>else if()</code>, and <code>else()</code> to model these options. Let’s say the accused person <strong>did</strong> break into the car, but did not take anything. We could model the options like this:</p>
<pre><code><span class="hljs-keyword">let</span> breaking = <span class="hljs-literal">true</span>;
</code></pre><pre><code><span class="hljs-keyword">let</span> theft = <span class="hljs-literal">false</span>;
</code></pre><pre><code><span class="hljs-keyword">if</span> (breaking &amp;&amp; theft){
</code></pre><pre><code>  convict(<span class="hljs-string">'felony'</span>);
</code></pre><pre><code>}
</code></pre><pre><code><span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(breaking){
</code></pre><pre><code>  convict (<span class="hljs-string">'misdemeanor'</span>);
</code></pre><pre><code>}
</code></pre><pre><code><span class="hljs-keyword">else</span>{
</code></pre><pre><code>  release();
</code></pre><pre><code>}
</code></pre><p>There are now three scenarios. If the first condition is satisfied, that code block will run. That means that the thief would be convicted of a felony. But, if only the value of the variable <code>breaking</code> can be evaluated as <code>true</code>, the person will still be convicted of a misdemeanor.</p>
<p>The judge is saying, “You need to show me evidence of both breaking and entering <strong>and</strong> theft if I am going to convict this person of a felony.”</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0*09AccMKv051RIVLG" alt="Image" width="800" height="413" loading="lazy"></p>
<p>The first <code>if()</code> statement will evaluate <code>true &amp;&amp; false</code>, which will be reduced to <code>false</code> since <code>false</code> takes precedence over <code>true</code> (remember, innocent until proven guilty).</p>
<p>This would still work if we used values that were “truthy” or “falsy”. Each one would be evaluated to <code>true</code> or <code>false</code> within the <code>if()</code> statement, and then JavaScript would decide which block to execute.</p>
<h3 id="heading-get-more-visual-tutorials">Get more visual tutorials</h3>
<p>Did you enjoy this guide? Give it a “clap”, or sign up below to get my latest tutorials on web development topics.</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
