title: Cannot update a variable inside a function
body: <p>I'm trying to update a variable with the result of a function, so it can be referenced elsewhere, but it doesn't update.</p>
  
  <pre><code>var total = 0;
  
  mainQuery.count({
      success: function (number) {
          console.log("results",number);
          total = number;
      }
  });
  
  console.log("total is",total);
  
  // console output:
  // results 164
  // total is 0
  </code></pre>
  
  <p>What is the correct way of doing this?</p>