Is the !! (not not) operator in JavaScript equivalent to reverse process of not operator?

JavascriptWeb DevelopmentFront End TechnologyObject Oriented Programming

<p>Yes, the not not operator is the reverse process of not operator. If any value is true then single ! (not) will return false and !! will return opposite value (true).</p><p>The not operator &minus;</p><pre class="result notranslate">var flag=true; console.log(!flag);</pre><p>The not not operator &minus;</p><pre class="result notranslate">var flag=true; console.log(!!flag);</pre><h2>Example</h2><p>Following is the code &minus;</p><!---<p><a href="" target="_blank" rel="nofollow" class="demo"><i class="fa-external-link"></i> Live Demo</a></p>---><pre class="prettyprint notranslate">var flag=true; console.log(&quot;The result of single !=&quot;) console.log(!flag); console.log(&quot;The result of single !!=&quot;) console.log(!!flag)</pre><p>To run the above program, you need to use the following command &minus;</p><pre class="result notranslate">node fileName.js. </pre><p>Here, my file name is demo247.js</p><h2>Output</h2><p>This will produce the following output on console &minus;</p><pre class="result notranslate">PS C:\Users\Amit\javascript-code&gt; node demo247.js The result of single != false The result of single !!= True</pre>
raja
Updated on 09-Nov-2020 06:25:30

Advertisements