title: Wait for Function to complete and then return a value
body: <p>I have this function <code>Offline.check();</code> , which takes 1 seconds to execute..So below function is not waiting for it and it always return false on first time.I used set time out..but thats always returning null.</p>
  
  <pre><code>  function checkstats()
  
      {
  
      Offline.check(); // This returns Offline.state=up  or down and it takes 1 seconds to complete.
  
      if(Offline.state=="up")
      {
      return true;
      }
  
      else
      {
      return false;
      }
  
      }
  
  var a = checkstats();
  </code></pre>