title: What exactly happens when awaiting a promise in JavaScript?
body: <p>One point that I can’t seem to find anywhere in documentation or related resources is what the procedure is, in regards to the calling function and the event loop, when JS hits the <code>await</code> keyword. </p>
  
  <p>Here’s what the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await" rel="nofollow noreferrer">specs</a> state:</p>
  
  <blockquote>
    <p>The await expression causes async function execution to pause until a Promise is resolved, that is fulfilled or rejected, and to resume execution of the async function after fulfillment. When resumed, the value of the await expression is that of the fulfilled Promise.</p>
  </blockquote>
  
  <p>That all makes sense, but what really is meant by pause? Does the function immediately return to the caller and then when the promise that’s being awaited resolves, it and the rest of the async method gets added to the microtask queue for handling? I know that <code>async/await</code> is syntactic sugar for the Promise API, so I’m assuming that this is sorta what happens, but I want to make sure I’m really understanding the “magic” that happens when an <code>await</code> is reached. </p>
  
  <p>From what I’ve read, this seems to be what’s done in C#, but I’m not exactly sure how it translates to JS. </p>