title: How to save results of a promise to a variable?
body: <p>I need to fetch some JSON data from an API and assign the result to a variable. I can see the array of data in the console, but [abc] is always set as a Pending promise. </p>
  
  <p>I've tried to assign [abc] instead of logging [data] or simply returning [data] but it's not working.
  Ideally, I would also want to stop the execution of the following code until I get the required data but with the code I have, the text gets logged before the data</p>
  
  <pre><code>async function fetchData() 
  {
    let response = await fetch('API');
    let data = await response.json();
    data = JSON.stringify(data);
    data = JSON.parse(data);
    return data;
  }
  
  let abc = await fetchData()
    .then(data =&gt; console.log(data)); 
  
  console.log('This should not be logged if 'abc' does not have the data i need')
  
  </code></pre>
  
  <p>(data => console.log(data))  ..>> here the data is the array I need but I have no idea on how to assign on a variable.</p>
  
  <p>I've looked for many solutions on the internet but I couldn't find anything that could help.</p>
  
  <p>EDIT 1: </p>
  
  <p>If I assign:
  let abc = await fetchData()
  without the then statement it throws me this error:
  Uncaught SyntaxError: await is only valid in async function</p>
  
  <p>If I then remove the await keyword it returns Promise without having it resolved.</p>