title: When should I store a function into a variable?
body: <p>I'm learning JavaScript at the moment and I don't quite understand when to write a function into a variable.</p>
  
  <p>For instance, both of the following code blocks do the exact same thing in Node.js:</p>
  
  <pre><code> var onReq = function(req, res) {
     res.write('Hello');
   };
  
   http.createServer(onReq).listen(3000);
  </code></pre>
  
  <p>and</p>
  
  <pre><code>function onReq(req, res) {
     res.write('Hello');
   }
  
   http.createServer(onReq).listen(3000);
  </code></pre>
  
  <p><br><br>Which is the best method to do according to best practices, and why?</p>