IIFE (Immediately Invoked Function Expression)
What is a good use case for an IIFE with async/await?
A good use case for an IIFE with async/await is to perform asynchronous initialization code at the top level of a script. Before top-level await was supported in JavaScript modules, wrapping asynchronous code in an async IIFE was the primary way to use await outside of an async function. For example: ```javascript (async function() { try { const data = await fetch('/api/data'); const result = await data.json(); console.log(result); // Initialize application with result } catch (error) { console.error('Failed to initialize:', error); } })(); ``` This pattern allows you to write clean, sequential-looking code for asynchronous operations without needing to create and name a separate function. It's especially useful for initialization code that needs to run immediately when a script loads.