
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
What are async methods in JavaScript?
The async function declaration as the name suggests defines an asynchronous function. This function returns an AsyncFunction object.
Syntax
Here’s the syntax −
async function functionname([param[, param[, ... param]]]) { statements to be executed }
Example
Let’ see an example, which prints the result after 5 seconds −
<html> <body> <script> function displayFunction(num) { return new Promise(resolve => { setTimeout(() => { resolve(num); }, 5000); }); } async function add2(num) { const x = displayFunction(7); const y = displayFunction(5); return num * await x * await y; } add2(15).then(result => { document.write("Multiplication Result (after 5 seconds): "+result); }); </script> </body> </html>
- Related Articles
- What are async generator methods in JavaScript?
- What are Async Streams in C# 8.0?
- Async/Await Functions in JavaScript
- What are the Important Array Methods in JavaScript?
- What are the methods of a boolean object in JavaScript?
- What are the methods of an array object in JavaScript?
- Explain Promise.any() with async-await in JavaScript?
- Explain Promise.race() with async-await in JavaScript?
- Explain Promise.all with async-await in JavaScript?
- Explain Promise.allSettled() with async-await in JavaScript?
- what are the differences between unshift() and push() methods in javascript?
- What are methods in Java?
- What are defender methods or virtual methods in Java?
- what are abstract methods in Java?
- What are vararg methods in Java?

Advertisements