await work in chrome console without async wrapper [closed]

别来无恙 提交于 2020-03-25 17:50:49

问题


I've read the MDN definition for await which is : "The await operator is used to wait for a Promise. It can only be used inside an async function."
which works in the editor. However in the chrome console I wrote an async function then in the global execution I typed await functionName and that works perfectly without needing to the async function wrapper, edit: is that supported in the chrome's console just ?

const asyncGreeting = async () => 'Greeting' 

then in the global execution

await asyncGreeting()

the result was "Greeting"


回答1:


Top-level await is a proposed addition to ECMAScript.

Chrome added support for it to the dev tools.

Hence you can see it working in your test.



来源:https://stackoverflow.com/questions/57459959/await-work-in-chrome-console-without-async-wrapper

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!