title: Wait for two async functions to finish then continue in Node.js
body: <p>I'm working on an application in Node.js where I'm calling an async function twice, and assign the value to a global variable.</p>
  
  <p>The issue is that I want to use the result of the two calls to do something else, but this something else doesn't wait for the result to be assigned.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>var a;
  var b;
  
  let x = 'abcd';
  foo(x).then(data=&gt;{
      a = data;
  });
  
  x = 'efgh';
  foo(x).then(data=&gt;{
      b = data;
  });
  
  console.log(a + b); // for example
  </code></pre>
  
  <p>How can I wait for the two functions to finish, before executing <code>a + b</code>?</p>