Skip to main content
1 of 7
T.J. Crowder
  • 1.1m
  • 19
  • 110
  • 139

This question may be better suited to Meta Stack Overflow.

The problem is that the version of babel-standalone used by Stack Snippets is (well) out of date and doesn't understand async/await. Amusingly, on any modern browser, if you untick the Babel box in the snippet, it'll work.

It also works if you use a current version of babel-standalone, like this:

<script type="text/babel">
function bar() {
  return new Promise((resolve,reject) => {
    setTimeout(()=> {
      resolve('resolved after 1500ms');
    },1500);
    // return resolve('resolved');
  });
}

async function foo() {
  const result = await bar();
  console.log(result);
}

foo();
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script>

T.J. Crowder
  • 1.1m
  • 19
  • 110
  • 139