title: JavaScript Variable undefined outside of function
body: <p>I have a script section in my html file where I create a new instance of my <code>gmap</code> object. Outside of the function <code>initMap()</code> the variable <code>gMap</code> is undefined although I declared it outside of the function.</p>
  
  <pre><code>var gMap;
  function initMap() {
      gMap = new gmap({
          //some Properties
      });
      console.log(gMap); //gMap is defined
  }
  console.log(gMap); //gMap is undefined
  </code></pre>
  
  <p>The function is called like this:</p>
  
  <pre><code>&lt;script async defer
    src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&amp;callback=initMap"&gt;
  &lt;/script&gt;
  </code></pre>
  
  <p>I also tried calling it through <code>$(document).ready</code> instead of google API callback but it changed nothing.</p>