How to call an async function?

according to async_function MDN

Return value

A Promise which will be resolved with the value returned by the async function, or rejected with an uncaught exception thrown from within the async function.

async function will always return a promise and you have to use .then() or await to access its value

async function getHtml() {
  const request = await $.get('')  
  return request

  .then((data) => { console.log('1')})
  .then(() => { console.log('2')});
// OR 

(async() => {
  await getHtml()  
<script src=""></script>

Leave a Comment