42
rated 0 times
[
44]
[
2]
/ answers: 1 / hits: 13389
/ 6 Years ago, sun, october 28, 2018, 12:00:00
If I define a function like this:
const getName = async () => await Promise.resolve('John');
When I try to call the getName function with async:
const name = await getName();
console.log(`Hi ${name}`);
It throws an error:
const name = await getName();
^^^^^
SyntaxError: await is only valid in async function
What I'm doing wrong?
More From » async-await