Functions that return a function - Javascript
<p>I' started learning JavaScript recently and I'm stuck up with this concept of 'Functions that return functions'. I'm referring the book 'Object Oriented Javascript' by Stoyan Stefanov. I have prior programming experience in Java, C and C++ and also 2 years of work experience applying my knowledge on the same.</p>

<p><strong>Snippet One:</strong>  </p>

<pre><code>function a() {

    alert('A!');

    function b(){
        alert('B!'); 
    }

    return b();
}

var s = a();
alert('break');
s();
</code></pre>

<p><strong>Output:</strong></p>

<pre><code>A!
B!
break
</code></pre>

<p><strong>Snippet Two</strong></p>

<pre><code>function a() {

    alert('A!');

    function b(){
        alert('B!'); 
    }

    return b;
}

var s = a();
alert('break');
s();
</code></pre>

<p><strong>Output:</strong></p>

<pre><code>A!
break
B!
</code></pre>

<p>Can someone please tell me the difference between returning <code>b</code> and <code>b()</code> in the above snippets? I tried searching for stuff on google but couldn't get any worthy links. I'd be glad if someone also provided me some links explaining the concept. Thanks and Regards.</p>
