Async/Await

What is it?

Async/await is modern JavaScript syntax for handling asynchronous operations in a more readable, synchronous-looking way. Functions marked with async automatically return Promises, and the await keyword pauses execution until a Promise resolves. This eliminates deeply nested callback functions (callback hell) and makes asynchronous code much easier to write, read, and debug.

Practical example

Instead of chaining multiple .then() calls, you write cleaner code: async function fetchUserData(userId) with try/catch for error handling. Inside, you await fetch to get the response, await response.json() to parse it, then await another fetch for related data. Each line executes in order, making the flow easy to follow, while errors are caught in a single catch block.

Test your knowledge

What must a function be declared as to use await inside it?

Ask Lex
Lex knows the context of this term and can give targeted explanations, examples, and extra context.
Tip: Lex replies briefly in the widget. For more detail, go to full screen mode.

Learn our language

Learn these terms from real professionals and take your skills further at KdG MCT.

Study at KdG