title: Assigning the result of an async function to a variable in a synchronous function
body: <p>I have an async function:</p>
  
  <pre><code>async function GetCounterFromSharepoint() {
    let counter = await getSharepointListItems('mylist');
  
    console.log('Got counter from sharepoint as ' + (await counter[0].CurrentValue));
  
    return counter[0].CurrentValue;
  }
  </code></pre>
  
  <p>The function works as expected, and the console.log statement prints <code>Got counter from sharepoint as 1500'</code></p>
  
  <p>I'm trying to call the function from the following function</p>
  
  <pre><code>function GetData(){
  
  let initialValue = GetCounterFromSharepoint()
  console.log('Value from SP is ' + initialValue);
  
  /* some other lines*/
  
  }
  </code></pre>
  
  <p>The console.log statement in this second function outputs <code>Value from SP is [object Promise]</code> and not the <code>1500</code> that i expect.</p>
  
  <p>This second console.log statement is also printed before the one in the async function. So i thought if i add a delay before it, it would give it time to resolve. So i first tried:</p>
  
  <p><strong>Using the <code>wait</code> function</strong> from <a href="https://developers.google.com/web/fundamentals/primers/async-functions" rel="nofollow noreferrer">developers.google.com</a></p>
  
  <pre><code>function wait(ms) {
    return new Promise((r) =&gt; setTimeout(r, ms));
  }
  
  let initialValue = GetCounterFromSharepoint()
  wait(2000) &lt; -- /*added this */
  console.log('Value from SP is ' + initialValue);
  </code></pre>
  
  <p>This had no effect. So I tried using <code>Promise.resolve</code> as follows:</p>
  
  <p><strong>using Promise.resolve</strong></p>
  
  <pre><code>console.log('Value from SP is ' + Promise.resolve(initialValue));
  </code></pre>
  
  <p>This gave the same output of <code>Value from SP is [object Promise]</code></p>
  
  <p><strong>Using await</strong></p>
  
  <pre><code>let initialValue = await GetCounterFromSharepoint()
  </code></pre>
  
  <p>This gave an error: <em>use of reserved keyword 'await'</em></p>
  
  <p>What do i need to do to get this to work, please?</p>