Why do I have to omit parentheses when passing a function as an argument?
<p>I am trying to wrap my head around as to why the following code results in a stack overflow when the parentheses are included, but do not when they omitted. </p>

<p>I am calling the function itself as an argument to setTimeout and it works without parantheses, but of course fails when I add them. It was my intuition to add the () after the function. Just hope somebody can clear this up for me. When are parans optional and not?</p>

<p>CASE 1:</p>

<pre><code>var a = 1;

function foo() {
    a++;
    document.write(a);
    setTimeout(foo(), 2000)
}​ 
// RangeError: Maximum call stack size exceeded
</code></pre>

<p>CASE 2:</p>

<pre><code>var a = 1;

function foo() {
    a++;
    document.write(a);
    setTimeout(foo, 2000)
}​
// parens are omitted on foo function and it works. 
</code></pre>
