how to asign a aync function to another code example
Example 1: async await anonymous function
let x = await (async function() {return "hello"})();
console.log(x);
console.log(await (async() => 'hello')())
Example 2: how to make an async function
function resolveAfter2Seconds() {
return new Promise(resolve => {
setTimeout(() => {
resolve('resolved');
}, 2000);
});
}
async function asyncCall() {
console.log('calling');
const result = await resolveAfter2Seconds();
console.log(result);
}
asyncCall();