title: Async/Await function execution sequence
body: <p>I state that I am not an expert in JavaScript, and I am now starting to deepen it.</p>
  <p>This post aims to clarify some doubts about the async / away functions that I'm just starting to deepen.</p>
  <p>The example below leaves me perplexed on the sequence of execution that seems, from the logs printed on the console, different from what I expected.</p>
  <p>Before exposing my doubt and my question for clarification I show you my example code:</p>
  <pre><code>async function fetchAlbum(id){
      let album;
      album = await fetch(albumUrl + '/' +id)
      .then( resp =&gt; resp.json())
      .then(albumcontent =&gt; albumcontent);
  
      console.log('Concrete Value 1',album); //Here is printed the concrete value thanks to await is not undefined
      
      return album; //Here the concrete value is wrapped by a promise (the value is returned to the caller in the form of a promise)
  }
  
  let alb = fetchAlbum(1);
  console.log('Promise 1',alb); //Print a promise... will be the first logged (!?)
  alb.then(alb =&gt; console.log('Concrete Value 2',alb)); //We have the album again as a concrete value (the album object)
  </code></pre>
  <p>I created an async function fetchAlbum within which I resolve the promises returned by the fetch () API by prefixing await.
  Therefore, I expect that at the call fetchAlbum (1) the code waits until the &quot;return album&quot; is performed inside the function async fetchAlbum (id). But in reality, this is not the case. Looking at the tracks on the console, I see:</p>
  <p>&quot;Promise 1&quot;, then &quot;Concrete Value 1&quot; and finally &quot;Concrete Value 2&quot;, the latter printed by the callback function of the promise returned by the async fetchAlbum function.</p>
  <p>What I understand is that JavaScript (ES6), just called an async function, returns the promise continuing with the flow of execution following the call let alb = fetchAlbum (1);
  and as soon as the chain of promises is finished, it will print &quot;Concrete Value 1&quot; and finally, it will pass for &quot;return album&quot;.</p>
  <p>The question is, assuming my guess is correct, how does JavaScript immediately return the promise (in pending state) without going through the &quot;return&quot;?</p>
  <p>I am still a bit confused and any suggestion to understand will be very welcome for me.</p>
  <p>I hope I have exposed my perplexity and my question in the most understandable way possible.</p>
  <p>Thanks a lot.</p>