title: How do I return from synchronous callback?
body: <p>First, have a look at this sample:</p>
  
  <pre><code>var calculate = function(callback) {
    // calculating...
    callback(5);
  }
  
  var parent = function() {
    var x = 0;
  
    var calculatedValue = calculate(function(output) {
      return output; // return #1
  
      x = output;
    });
  
    return x; // return #2
  
    return calculatedValue; // return #3
  }
  </code></pre>
  
  <p>My objective is to "calculate" a value within the <code>calculate</code> function, and this value must be returned by the <code>parent</code> function.</p>
  
  <p>Where should I place the return statement, and what should I return with it, in order to achieve this?</p>
  
  <p>I tried 3 cases:</p>
  
  <p><code>return #1</code>
  Here the <code>output</code> value is returned by the <code>callback</code> function, and not the <code>parent</code> function, so parent returns undefined.</p>
  
  <p><code>return #2</code>
  Here the value of x is returned before executing the <code>callback</code> function, so parent returns 0.</p>
  
  <p><code>return #3</code> + <code>return #1</code>
  Here, I tried to return the <code>output</code> from the <code>callback</code>, and then (thinking that the return value of callback may somehow become the return value of the <code>calculate</code> itself), returned the <code>calculatedValue</code>, but again, parent returns undefined.</p>
  
  <p>Please suggest a way, and plunk's over <a href="http://plnkr.co/edit/WdF8TzxPUPcIZDIVY94O?p=preview" rel="nofollow">here</a></p>