Why the following snippet won't work here on StackOverflow?
I'm trying to add some example of basic async/await and returned promises.
This exact same piece of code works just fine on my dev environment, I'm using Babel, but I've seen snippets with async await functions here on SO before.
What's happening?
It gives the error:
{
"message": "Script error.",
"filename": "",
"lineno": 0,
"colno": 0
}
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();