Undefined variables, value == false versus !value
<p>I have a problem with a very simple piece of code written in Javascript, could you help me please?</p>

<p>Here's what I think I have understand so far about javascript and variables:</p>

<ul>
<li>An undefined value is evaluated to false in a boolean operation</li>
<li>By using a == operator in a comparation, you're asking if two values are comparable regardless of their types</li>
</ul>

<p>I found an exercise file in a online course and I tried to do it, but I didn't got the same result expected in the lesson; the main problem was that I was comparing the value through a "if value == false { ... }" while the solution was using a "if !value { ... }"</p>

<p>So I decided to write a very short code in order to try it by myself, but I'm getting mixed results. Here in the example below I would expect this JS code to generate two identical alerts ("foo is equal to false"), but instead the first if statement returns "foo IS NOT equal to false" while the second if returns (as expected) "foo is equal to false".</p>

<p>This is what I written:</p>

<pre><code>var foo = undefined;

if (foo == false) {
  alert("foo is equal to false");
} else {
  alert("foo is not equal to false"); // Javascript executes this row
}

if (!foo) {
  alert("foo is equal to false");  // Javascript executes this row
} else {
  alert("foo is not equal to false");
}
</code></pre>

<p>AFAIK the two IFs should do the same work, and infact when I tried it by replacing in the first line the value "var foo = undefined;" with "var foo = 0;" it worked as expected, and 0 is another value that should be evaluated to false, or at least this is what I remember.</p>

<p>Could you tell me what I'm doing wrong?</p>
