title: Why use async/await, it makes code work like sync
body: <p>If you use promise's <code>then()</code> syntax, you can truly run codes concurrently.</p>
  <p>See this example.</p>
  <pre class="lang-js prettyprint-override"><code>async function asyncFunc() {
    return '2';
  }
  
  console.log('1')
  asyncFunc().then(result =&gt; console.log(result))
  console.log('3')
  </code></pre>
  <p>this prints <code>1</code> -&gt; <code>3</code> -&gt; <code>2</code> because <code>asyncFunction()</code> runs in &quot;async&quot; and rest of code (<code>'3'</code>) runs without delay.</p>
  <p>But if you use <code>async</code>/<code>await</code> syntax, doesn't it work like plain ordinary &quot;sync&quot; code?</p>
  <pre class="lang-js prettyprint-override"><code>async function asyncFunc() {
    return '2';
  }
  
  console.log('1')
  const result = await asyncFunc()
  console.log(result)
  console.log('3')
  </code></pre>
  <p>this would print <code>1</code>-&gt;<code>2</code>-&gt;<code>3</code> because it &quot;defers&quot; rest of the code to &quot;await&quot; asyncFunction()</p>
  <p>So I'm curious about the purpose of <code>async</code>/<code>await</code> syntax. I guess it allows you to use async functions like sync function. With <code>async</code>/<code>await</code>, I can easily see how my code runs because it has the same flow as plain sync code. But then, why not just use sync code in the first place?</p>
  <p>But I'm sure I'm missing something here right? What is the purpose of <code>async</code>/<code>await</code> syntax?</p>