title: What are boolean evaluation rules in Javascript?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/7496727/why-does-0-a-b-behave-different-than-0-true-a-b">Why does (‘0’ ? ‘a’ : ‘b’) behave different than (‘0’ == true ? ‘a’ : ‘b’)</a>  </p>
  </blockquote>
  
  
  
  <p>I'm currently learning Javascript and so far am pleased about the language.</p>
  
  <p>This morning, when writing a test, I realized something I can't explain:</p>
  
  <p>When evaluating boolean expressions, we have:</p>
  
  <pre><code>// a &amp;&amp; b returns b in case a &amp;&amp; b are evaluated to true: OK
  '2' &amp;&amp; '3' =&gt; '3'
  '3' &amp;&amp; '2' =&gt; '2'
  
  // a &amp;&amp; b returns a in case a is evaluated to false, b otherwise: OK
  false &amp;&amp; '' =&gt; false
  '' &amp;&amp; false =&gt; ''
  
  // '' and '0' are evaluated to false in a boolean context: OK
  '' == false =&gt; true
  '0' == false =&gt; true
  
  // Here is the "problem":
  '' &amp;&amp; '0' =&gt; '' // To be expected: both operands evaluate to false
  '0' &amp;&amp; '' =&gt; '' // What ?!!
  </code></pre>
  
  <p>So my question is simple: why does <code>'0' &amp;&amp; ''</code> return <code>''</code> ?</p>
  
  <p>I would expect both operands to evaluate to false but it seems in that context <code>'0'</code> does not. Why is so ?</p>