title: javascript wait for function to finish execution before continuing
body: <p>I am trying to set a global variable within a function, but the code continues before the variable has been updated. 
  e.g.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>        var username = 'Example';
   const fetch = require('node-fetch');
   var num = 1234;
   var uuidP;
   const request = async () =&gt; {
    const response = await fetch(`https://api.mojang.com/users/profiles/minecraft/${username}`);
    const json = await response.json();
    uuidP = json.id;
   }
   request();
  
   console.log(num); //returns 1234
   console.log(uuidP); //returns udefined</code></pre>
  </div>
  </div>
  </p>