Javascript function as a parameter to another function?
<p>I'm learning lots of javascript these days, and one of the things I'm not quite understanding is passing functions as parameters to other functions. I get the <em>concept</em> of doing such things, but I myself can't come up with any situations where this would be ideal.</p>

<p>My question is:</p>

<p>When do you want to have your javascript functions take another function as a parameter? Why not just assign a variable to that function's return value and pass that variable to the function like so:</p>

<pre><code>// Why not do this
var foo = doStuff(params);
callerFunction(foo);

//instead of this
callerFunction(doStuff);
</code></pre>

<p>I'm confused as to why I would ever choose to do things as in my second example. </p>

<p>Why would you do this? What are some use cases?</p>

<p>Thanks!!</p>
