title: Higher-order functions in Javascript
body: <p>I am reading Eloquent JavaScript (<a href="http://eloquentjavascript.net/2nd_edition/preview/05_higher_order.html#c_JVArXJ1Pc1" rel="noreferrer">The new edition</a>) and I reached the part on higher order functions and I'm confused on what's happening in the following code. </p>
  
  <pre><code>function noisy(f) {
    return function(arg) {
      console.log("calling with", arg);
      var val = f(arg);
      console.log("called with", arg, "- got", val);
      return val;
    };
  }
  noisy(Boolean)(0);
  // → calling with 0
  // → called with 0 - got false
  </code></pre>
  
  <ol>
  <li><p>Why is the call to the function noisy like this? Is (Boolean) a cast? A cast for what? the return value? or the argument? why not (Boolean)noisy(0) if its the return value. Or noisy((Boolean) 0) if the argument is the one being casted.</p>
  
  <pre><code>noisy(Boolean)(0)
  </code></pre></li>
  <li><p>What is happening in this line? Where is f() even defined?</p>
  
  <pre><code>var val = f(arg);
  </code></pre></li>
  </ol>