await outside of async function doesn't throw error in console

  • A+
Category:Languages

MDN says:

Remember, the await keyword is only valid inside async functions. If you use it outside of an async function's body, you will get a SyntaxError.

But that's not true.

Try this code in DevTools console, no errors, just result:

async function a(val) { return val; } await a(10) // await is not inside async function 10 

What's wrong with the code or docs?

 


It looks like it has been supported since 11/08/2017:

https://chromium.googlesource.com/chromium/src.git/+/e8111c396fef38da6654093433b4be93bed01dce

If you spy the

ConsoleModel.js

at line 129, they have the function for evaluating expressions marked as async:

async evaluateCommandInConsole 

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: