title: javascript: function returns value undefined when assigned to variable
body: <p>I'm trying to assign a function's return value to a variable, using <a href="https://stackoverflow.com/questions/17371982/javascript-function-returning-undefined">this stackOverflow article</a> as a template. Here's my code: </p>
  
  <pre><code>var host = getHostName(djId, function(name) {
      return name;
  });
  console.log(host);    // undefined :(
  
  
  function getHostName(id, cb) {
      var reply;
      userColl.findById(id, function (err, dj) {
          if (err) {
              reply = "db error";
          } else {
              reply = dj.firstName + ' ' + dj.lastName;
          }
          console.log(reply + ' reply');    // working as expected!
          cb(reply);
      });
  }
  </code></pre>
  
  <p>the console.log(reply) is working as expected but <code>host</code> is still undefined when i try t call the function. what gives?</p>