How to detect support for top level await in Javascript?

192 Views Asked by At

ECMAScript 2022 introduced await at the top level of a module. In older browser versions (eg Safari 14) it throws a syntax error. I would like to detect support for TLA so I can provide an alternative.

Since this is a syntax feature I tried to eval TLA in a try/catch-block. However this will always throw a syntax error, since await is only valid at the top level, not inside try and eval.

0

There are 0 best solutions below