3 ms·
The use case is not needing to wrap your code in an IIFE [1] when you would have a top-level await statement. It is useful in entry point of apps where you migh
by ratww 6y ago
The use case is not needing to wrap your code in an IIFE [1] when you would have a top-level await statement. It is useful in entry point of apps where you might need anything that uses async. It's also useful for having async modules. [2]
They're also very helpful for debugging. Using await something in the console is way more convenient than something.then().
[1] https://developer.mozilla.org/en-US/docs/Glossary/IIFE https://developer.mozilla.org/en-US/docs/Glossary/IIFE
[2] https://github.com/tc39/proposal-top-level-await/blob/HEAD/README.md https://github.com/tc39/proposal-top-level-await/blob/HEAD/R...