title: Closure in Javascript with multiple brackets
body: <p>Could any one explain how this function alert, when more no of brackets of parameters are passed. I could not able to understand it clearly.</p>
  
  <pre><code>function sum(a) {
  
    var sum = a
  
    function f(b) {
      sum += b
      return f
    }
  
    f.toString = function() { return sum }
  
    return f
  }
  
  alert( sum(1)(2) )  // 3
  alert( sum(5)(-1)(2) )  // 6
  alert( sum(6)(-1)(-2)(-3) )  // 0
  alert( sum(0)(1)(2)(3)(4)(5) )  // 15
  </code></pre>