That's unless you have top-level await support in your environment (which Node doesn't but the esm package can be configured to provide or if you transpile)
Also, just a side note, I just realized now that top-level await is essentially a glorified way of writing top-level synchronous code. That's kind of strange... 🤔
You could argue that the following syntax is subjectively easier to grok, because it's explicit about the definition and execution of the async function main. However, there's no technical advantage of one syntax vs the other.
The one place where IIFEs can still be useful is surprisingly async/await in Node.
You can't use await outside of async so you end up doing something like:
That's unless you have top-level await support in your environment (which Node doesn't but the
esm
package can be configured to provide or if you transpile)Oh, yeah. How could I forget about that?
Also, just a side note, I just realized now that top-level await is essentially a glorified way of writing top-level synchronous code. That's kind of strange... 🤔
You could argue that the following syntax is subjectively easier to grok, because it's explicit about the definition and execution of the async function
main
. However, there's no technical advantage of one syntax vs the other.