Tag Archives: JS async await Error

JS async await Error: Uncaught SyntaxError: await is only valid in async functions and the top level bodies of modules

Uncaught SyntaxError
Uncaught SyntaxError: await is only valid in async functions and the top level bodies of modules
await the top level bodies of modules
Can not Run normally

<script type="text/javascript">
// Uncaught SyntaxError: await is only valid in async functions and the top level bodies of modules
let x = await tools();
console.log(x);
</script>

After modification

reference resources

<script type="text/javascript">
// demo
(async () => {
    let x = await tools();
    console.log(x);
})();
</script>