<p>I understand that using the "===" compares type, so running the following code results in "not equal" because it's comparing a number type to a string type.</p>

<pre><code>var a = 20;
var b = "20";
    if (a === b) {
        alert("They are equal");
    } else {
        alert("They are not equal");
}
</code></pre>

<p>But I dont understand how using the "==" to compare only the value results in the "They are equal" message.</p>

<pre><code>var a = 20;
var b = "20";
    if (a == b) {
        alert("They are equal");
    } else {
        alert("They are not equal");
}
</code></pre>

<p>How are the values equal? Isn't the string "20" stored as the ASCII characters 50 and 48 (0110010 and 0110000 in binary) and 20 stored as the actual binary number 0010100?</p>

<p>EDIT: Thanks everyone! I think all the responses are great and have helped me understand this much better.</p>

The
```
==
```
operator compares only the values of the variables. If the types are different, a conversion is operated. So the number 20 is converted to the string "20" and the result is compared.
The
```
===
```
operator compares not only the values, but also the types, so no cast is operated. In this case
```
"20" !== 20
```