title: scope calling functions inside functions
body: <p>Hope somebody finds the time to explain little about functions in functions and scoping.
  I am trying to understand little more on functions and scope of variables and found a quite good tutorial, but this part I just do not get.</p>
  
  <p><strong>The task:</strong></p>
  
  <p>Create a function sum that will work like that: <code>sum(a)(b) = a+b</code> and accepts any number of brackets. Examples:</p>
  
  <pre><code>sum(1)(2) == 3
  sum(5)(-1)(2) == 6
  </code></pre>
  
  <p><strong>The solution:</strong></p>
  
  <pre><code>function sum(a) {
  
      var sum = a;
  
      function f(b){
          sum += b;
          return f;
      }
  
      f.toString = function() { return sum };
  
      return f;         //line 12
  }
  
  alert( sum(1)(2) );   // 3e
  </code></pre>
  
  <p><strong>The Explanation:</strong></p>
  
  <p>To make <code>sum(1)</code> callable as <code>sum(1)(2)</code>, it must return a function.
  The function can be either called or converted to a number with <code>valueOf</code>.
  The solution is really self-explanatory:</p>
  
  <p><strong>My interpretation:</strong></p>
  
  <p>This <code>f</code> in <code>function f(b)</code> returned to the scope, which is from line 02 - 12.
  The <code>f</code> in <code>f.toString</code>, is the currently returned <code>f</code> from <code>function(b)</code>
  The next <code>return f</code> returns to the scope which is outside the function <code>sum(a)</code>.</p>
  
  <p><strong>Problem:</strong></p>
  
  <p>I cannot figure out, where I need to think differently, because like I described above, the function would not be called again, so where is the part of the code, that make the 'several parentheses' possible?</p>
  
  <p>Moreover, did I correctly assume where the <code>f</code>s are returned? Would be great if somebody would give some explanations.</p>