admin管理员组

文章数量:1290955

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"

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"

Share Improve this question edited Aug 12, 2019 at 15:44 Mustafa Alfar asked Aug 12, 2019 at 11:01 Mustafa AlfarMustafa Alfar 1852 gold badges5 silver badges16 bronze badges 4
  • 3 So the Chrome REPL is weird. Did you have a question? (I see a question mark in your post, but it follows a statement). – Quentin Commented Aug 12, 2019 at 11:04
  • 5 This feature was added in Chrome 62 developers.google./web/updates/2017/08/… – Roland Starke Commented Aug 12, 2019 at 11:05
  • 1 As Roland wrote, this works already in the console but not for the normal code execution. However, there is a proposal for that github./tc39/proposal-top-level-await – str Commented Aug 12, 2019 at 11:09
  • I had same question and this quetsion helps. + 1 – Rick Commented Mar 24, 2020 at 5:03
Add a ment  | 

1 Answer 1

Reset to default 8

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.

本文标签: javascriptawait work in chrome console without async wrapperStack Overflow