<p>Do you know what value will be alerted if the following is executed as a JavaScript program?</p> <pre><code>var foo = 1; function bar() { if (!foo) { var foo = 10; } alert(foo); } bar();</code></pre> <p>If it surprises you that the answer is “10”, then this one will probably really throw you for a loop:</p> <pre><code>var a = 1; function b() { a = 10; return; function a() {} } b();