Async and Await in JavaScript Last Updated : 31 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Async and Await in JavaScript are used to simplify handling asynchronous operations using promises. By enabling asynchronous code to appear synchronous, they enhance code readability and make it easier to manage complex asynchronous flows. JavaScript async function fetchData() { const response = await fetch("https://jsonplaceholder.typicode.com/posts/1"); const data = await response.json(); console.log(data); } fetchData(); Output:{ userId: 1, id: 1, title: ....', body: ....}Syntax: async function functionName() { try { const result = await someAsyncFunction(); console.log(result); } catch (error) { console.error("Error:", error.message); }}Async FunctionThe async function allows us to write promise-based code as if it were synchronous. This ensures that the execution thread is not blocked. Async functions always return a promise. If a value is returned that is not a promise, JavaScript automatically wraps it in a resolved promise.Syntax:async function myFunction() { return "Hello";} javascript const getData = async () => { let data = "Hello World"; return data; } getData().then(data => console.log(data)); OutputHello WorldAwait KeywordThe await keyword is used to wait for a promise to resolve. It can only be used within an async block. Await makes the code wait until the promise returns a result, allowing for cleaner and more manageable asynchronous code. javascript const getData = async () => { let y = await "Hello World"; console.log(y); } console.log(1); getData(); console.log(2); Output1 2 Hello WorldThe async keyword transforms a regular JavaScript function into an asynchronous function, causing it to return a Promise.The await keyword is used inside an async function to pause its execution and wait for a Promise to resolve before continuing.Error Handling in Async/AwaitJavaScript provides predefined arguments for handling promises: resolve and reject.resolve: Used when an asynchronous task is completed successfully.reject: Used when an asynchronous task fails, providing the reason for failure. JavaScript async function fetchData() { try { let response = await fetch('https://api.example.com/data'); let data = await response.json(); console.log(data); } catch (error) { console.error('Error fetching data:', error); } } async/await Visit Course async/await Async and Await in JavaScript Comment More info K KhushalAgarwal Follow Improve Article Tags : JavaScript Web Technologies javascript-functions Explore JavaScript BasicsIntroduction to JavaScript4 min readJavaScript Versions2 min readHow to Add JavaScript in HTML Document?3 min readJavaScript Syntax6 min readJavaScript Output4 min readJavaScript Comments2 min readVariables & DatatypesVariables and Datatypes in JavaScript6 min readGlobal and Local variables in JavaScript4 min readJavaScript Let6 min readJavaScript const5 min readJavaScript Var Statement7 min readOperatorsJavaScript Operators5 min readOperator precedence in JavaScript2 min readJavaScript Arithmetic Operators5 min readJavaScript Assignment Operators5 min readJavaScript Comparison Operators5 min readJavaScript Logical Operators5 min readJavaScript Bitwise Operators5 min readJavaScript Ternary Operator4 min readJavaScript Comma Operator2 min readJavaScript Unary Operators4 min readJavaScript in and instanceof operators3 min readJavaScript String Operators3 min readStatementsJavaScript Statements4 min readJavaScript if-else3 min readJavaScript switch Statement4 min readJavaScript Break Statement2 min readJavaScript Continue Statement1 min readJavaScript Return Statement4 min readLoopsJavaScript Loops3 min readJavaScript For Loop4 min readJavaScript While Loop3 min readJavaScript For In Loop3 min readJavaScript for...of Loop3 min readJavaScript do...while Loop4 min readPerformance & DebuggingJavaScript | Performance4 min readDebugging in JavaScript4 min readJavaScript Errors Throw and Try to Catch2 min readObjectsObjects in Javascript4 min readObject Oriented Programming in JavaScript3 min readJavaScript Objects6 min readCreating objects in JavaScript5 min readJavaScript JSON Objects3 min readJavaScript Object Reference4 min readFunctionsFunctions in JavaScript5 min readHow to write a function in JavaScript ?4 min readJavaScript Function Call2 min readDifferent ways of writing functions in JavaScript3 min readDifference between Methods and Functions in JavaScript3 min readExplain the Different Function States in JavaScript3 min readJavaScript Function Complete Reference3 min readArraysJavaScript Arrays7 min readJavaScript Array Methods7 min readBest-Known JavaScript Array Methods6 min readImportant Array Methods of JavaScript7 min readJavaScript Array Reference4 min readStringJavaScript Strings6 min readJavaScript String Methods9 min readJavaScript String Reference4 min read Like