Why does javascript returns true for these three statements
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/7605011/why-is-0-true-in-javascript">Why is 0 == &ldquo;&rdquo; true in JavaScript</a>  </p>
</blockquote>



<p>Okay, so basically I was trying out if statement in javascript and I found out that it returns result incorrectly. Well maybe not incorrectly, but returned result is strange.</p>

<p>So basically here is my jsfiddle where you can see everything - </p>

<p><a href="http://jsfiddle.net/g5hRa/" rel="nofollow">http://jsfiddle.net/g5hRa/</a></p>

<p>and also I'll paste it here, so you don't have to check it there -</p>

<pre><code>$(document).ready(function() {
    if('' == 0) {
        $("#text").append("1) '' == 0 true&lt;br /&gt;");
    } else {
        $("#text").append("1) '' == 0 false&lt;br /&gt;");    
    }
    if(0 == '') {
        $("#text").append("2) 0 == '' true&lt;br /&gt;");
    } else {
        $("#text").append("2) 0 == '' false&lt;br /&gt;");
    }
    if(0 == "0") {
        $("#text").append("2) 0 == '0' true&lt;br /&gt;"); 
    } else {
        $("#text").append("2) 0 == '0' false&lt;br /&gt;");
    }
    $("#text").append("With === -&lt;br /&gt;");
    if('' === 0) {
        $("#text").append("1) '' === 0 true&lt;br /&gt;");
    } else {
        $("#text").append("1) '' === 0 false&lt;br /&gt;");    
    }
    if(0 === '') {
        $("#text").append("2) 0 === '' true&lt;br /&gt;");
    } else {
        $("#text").append("2) 0 === '' false&lt;br /&gt;");
    }
    if(0 === "0") {
        $("#text").append("2) 0 === '0' true&lt;br /&gt;"); 
    } else {
        $("#text").append("2) 0 === '0' false&lt;br /&gt;");
    }
});​
</code></pre>

<p>returns -</p>

<pre><code>1) '' == 0 true
2) 0 == '' true
2) 0 == '0' true
With === -
1) '' === 0 false
2) 0 === '' false
2) 0 === '0' false
</code></pre>

<p>why does all statements with == returns true? They aren't the same, in first example as we can see if empty string is equal to zero - it returns true, next statement if zero is equal to empty string  - also true and in last example if string (zero) is equal to zero and it's also true. All of these examples should return false.</p>

<p>When we use === it returns correct answer for all statements.</p>

<p>I would like to find out why it does return true when using is equal to?</p>
