DEV Community

Discussion on: JavaScript error handling with better `dx`

Collapse
 
joelnet profile image
JavaScript Joel

You cannot use async/await in the global scope. By wrapping your code in an async function, this trick will let you use await.

Collapse
 
puritanic profile image
Darkø Tasevski

Are you sure about that? I know that you can't use await without async but if I remember correctly I've used async function in top-level scope a few times 🤔

Anyway, I was thinking about that semicolon at the beginning which purpose is to guard against AST, confusing and ugly syntax IMO.

Thread Thread
 
joelnet profile image
JavaScript Joel

Are you sure about that?

You can test by pasting an await command into the browser console.

Anyway, I was thinking about that semicolon at the beginning

Ahh ya. It's just a guard.