weird behavior of JS functions in an if statement, WHY?
<p>Why the following code will return  <em>“obvious”</em>, <em>“surprise!”</em> (and lastly <em>“how come?”</em>). It should  return <em>"expected"</em>, isn't it?<br>
In the first <code>if</code> we used anonymous functions, in the second we used 'named' functions.</p>

<pre><code>var a = 5;
if (a == 5) {
    var b = function () {
        return "obvious";
    };
} else {
    var b = function () {
        return "never";
    };
}

if (a == 5) {
    function c() {
        return "expected";
    }
} else {
    function c() {
        return "surprise!";
    }
    function d() {
        return "how come?";
    }
}

alert(b());
alert(c());
alert(d());
</code></pre>

<p>So this means, <code>function a(){} is NOT equal to var a = function (){}</code>.</p>

<p>So, the second question, why JS needs this peculiar behavior? What's the benefit of this ? </p>
