title: Why await only works in async function in javascript?
body: <p>Just going through this <a href="https://javascript.info/async-await" rel="noreferrer">tutorial</a>, and it baffles me to understand why <code>await</code> only works in <code>async</code> function.</p>
  
  <p>From the tutorial:</p>
  
  <blockquote>
    <p>As said, await only works inside async function.</p>
  </blockquote>
  
  <p>From my understanding, <code>async</code> wraps the function return object into a Promise, so the caller can use <code>.then()</code></p>
  
  <pre><code>async function f() {
    return 1;
  }
  
  f().then(alert); // 1
  </code></pre>
  
  <p>And <code>await</code> just waits for the promise to settle within the <code>async</code> function. </p>
  
  <pre><code>async function f() {
  
    let promise = new Promise((resolve, reject) =&gt; {
      setTimeout(() =&gt; resolve("done!"), 1000)
    });
  
    let result = await promise; // wait till the promise resolves (*)
  
    alert(result); // "done!"
  }
  
  f();
  </code></pre>
  
  <p>It seems to me their usage are not related, could someone please explain?</p>