Search code examples
javascriptasynchronousgoogle-chrome-devtools

await work in chrome console without async wrapper


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"


Solution

  • 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.