We can only execute await
inside an async function. If you try to use await without an async function, it will result in an error.
Solution: One good option to address this issue is by using IIFE (Immediately Invoked Function Expression).
(async function(){
let a = await testSleep();
console.log(a);
let b = await testSleep();
console.log(b);
})();
Top comments (0)