title: Javascript method with XMLHttpRequest returning undefined
body: <p>I have the following method that should return either true or false:</p>
  
  <pre><code>theMethod() {
      const httpRequest = new XMLHttpRequest();
      httpRequest.open("GET", 'http://someurl.com', true);
      httpRequest.send();
      httpRequest.onreadystatechange = function() {
      if (this.readyState == 4 &amp;&amp; this.status == 200) {
          return true;
      } else {
          return false;
      }
      };
  }
  </code></pre>
  
  <p>In both cases it's returning 'undefined'</p>
  
  <p>How can I fix this?</p>