How does async/await work and how do you handle errors?
Suggested answer
async functions always return a Promise. await pauses execution within an async function until the awaited Promise settles. Error handling: wrap in try/catch: try { const data = await fetchData(); } catch (err) { console.error(err); } finally { cleanup(); }. Uncaught rejections in async functions become rejected Promises — handle them at the call site or with .catch(). Sequential vs Parallel: Sequential: const a = await fetch1(); const b = await fetch2(); (fetch2 starts after fetch1 completes). Parallel: const [a, b] = await Promise.all([fetch1(), fetch2()]); (both start simultaneously — faster). In LWC, Apex method calls return Promises and are called with async/await in event handlers: async handleClick() { this.data = await getRecords(); }.
Practice content for interview preparation; not an official vendor answer. Verify details against current product documentation.
Community comments (0)
No comments yet.
Sign in or create a free account to add a comment. Comments are moderated before they appear.