await anonymous function javascript code example

Example 1: async await anonymous function

let x = await (async function() {return "hello"})();
console.log(x);
// or
console.log(await (async() => 'hello')())

Example 2: await async iife javascript

const timeouttt = () => {
    return new Promise(resolve => {
        setTimeout(() => {
            console.log('hey');
            resolve('heyyy');
        }, 1000);
    });
};
const hello5 = async () => {
    console.log('hi iqbal');
    let y = await (async function () {
        let x = await timeouttt();
        console.log(x);
        console.log('hola');
        return 5;
    })();
    console.log(y);
    console.log('vola');
};

hello5()