title: Can't change global variable inside function (JavaScript)
body: <p>I have a global variable called <em>result</em> and a function, with the purpose of changing the value of result. here's the code I've tried:</p>
  
  <pre><code>checkdate();
  
  function checkdate() {
      //defining startdate,enddate,hotel_id
  
      $.ajax({
      method: 'GET',
      url: '/checkdate',
      data: {startdate : startdate, enddate : enddate, checkroom : 1, hotel_id : hotel_id},
      success: function(response){
          storeResponse(response);
      }
      });
  }
  
  var result = [];
  function storeResponse(response) {
      window.result = response;
  }
  alert(result);
  </code></pre>
  
  <p>The alert returns nothing, however if I put the alert INSIDE the function, it returns <em>response</em> alright. This seems to be easy but I can't figure it out.</p>
  
  <p>The function is invoked before all this code.</p>