Difference between eval and setTimeout execute string code
<p>I know that <code>eval</code> and <code>setTimeout</code> can both accept a string as the (1 st) parameter, and I know that I'd better not use this. I'm just curious why is there a difference:</p>

<pre><code>!function() {
    var foo = 123;
    eval("alert(foo)");
}();

!function() {
    var foo = 123;
    setTimeout("alert(foo)", 0);
}();
</code></pre>

<p>the first would work, and the second will give an error: <code>foo is not defined</code></p>

<p>How are they executed behind the scene? </p>
