title: How async/await and Promise work in TypeScript
body: <p>I have a small function to learn how async,await and promise workes here.</p>
  
  <pre><code>function delay(ms: number) {
      return new Promise&lt;void&gt;(function(resolve) {
         setTimeout(resolve, ms);
      });
  }
  
  async function asyncAwait() {
      console.log("A");
  
      await delay(1000);
      console.log("B");
  
      await delay(1000);
      console.log("C");
  }
  
  asyncAwait();
  console.log("D");
  </code></pre>
  
  <p>My understanding , the workflow would be like,</p>
  
  <p>call <code>asyncAwait();</code> first, then print <code>A</code>, then wait for 1s and print <code>B</code> then wait for another 1s and print <code>C</code> at last print <code>D</code>.</p>
  
  <p>but my output is like, </p>
  
  <pre><code>A
  D
  B
  C
  </code></pre>
  
  <p>I don't know why <code>console.log("D")</code> is displaying second.</p>
  
  <p>can anyone explain the above code ?</p>
  
  <p>thanks in advance</p>