js async await Uncaught SyntaxError
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
- 无法运行
<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>
修改后
- 参考
<script type="text/javascript">
// demo
(async () => {
let x = await tools();
console.log(x);
})();
</script>