What does "add()();" mean in JavaScript?
<p>I'm getting different values for <code>i</code> by calling <code>add</code> function differently. Could someone explain what's happening here?  </p>

<pre><code>var i = 0;
var add = function() {
    ++i;
    return function() {
        i++;
        return function() {
            i++;
            add();
        }
    }
 };
add(); // i = 1;
add()(); // i = 2;        
add()()(); // i = 4;
</code></pre>

<p>​</p>
