JavaScript async function expression Last Updated : 19 Jun, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report An async function expression is used to define an async function inside an expression in JavaScript. The async function is declared using the async keyword or the arrow syntax. Syntax: async function function_name (param1, param2, ..., paramN) { // Statements}Parameters: function_name: This parameter holds the function name. This function name is local to the function body. If the function name is omitted then it becomes an anonymous function.paramN: It is the name of the parameter that is to be passed into the function.Statements: It contains the body of the function.Return Value: It returns a promise to return the value or else throws an exception, whenever an error occurs. Example 1: In this example "GeeksforGeeks" is printed first and after an interval of 1000 ms, "GFG" is printed. javascript function cb() { return new Promise(function (resolve, reject) { setTimeout(function () { resolve("GFG") }, 1000) }) } async function course() { console.log("GeeksforGeeks"); const result = await cb(); console.log(result); } course(); Output: GeeksforGeeksGFGExample 2: Here, a file is made gfg.txt and as soon as the file is read it prints "Read the file" in the console. Else it prints an "error" when either the location of the file is wrong or it is not unable to read the file due to any other reason. javascript async function gfg() { try { let f1 = await fs.promises.readFile("gfg.txt") console.log("Read the file") } catch (err) { console.log("error"); } } gfg(); Output: When the file read: Read the fileWhen a file is not read(error thrown) errorExample 3: This is an example of an async function working in parallel. javascript function cb() { return new Promise(function (resolve, reject) { setTimeout(function () { resolve("GFG") }, 2000) }) } function cb1() { return new Promise(function (resolve, reject) { setTimeout(function () { resolve("GFG1") }, 1000) }) } async function course() { console.log("GeeksforGeeks"); const result1 = await cb1(); const result = await cb(); console.log(result1); console.log(result); } course(); Output: GeeksforGeeksGFG1GFGSupported Browsers: Google Chrome 55 and aboveEdge 15 and aboveFirefox 52 and aboveSafari 10.1 and aboveOpera 42 and above Comment More infoAdvertise with us Next Article Asynchronous JavaScript R riarawal99 Follow Improve Article Tags : JavaScript Web Technologies javascript-basics Similar Reads JavaScript function* expression The function* is an inbuilt keyword in JavaScript which is used to define a generator function inside an expression. Syntax: function* [name]([param1[, param2[, ..., paramN]]]) { statements}Parameters: This function accepts the following parameter as mentioned above and described below: name: This p 2 min read JavaScript Function Expression A function expression is a way to define a function as part of an expression making it versatile for assigning to variables, passing as arguments, or invoking immediately.Function expressions can be named or anonymous.They are not hoisted, meaning they are accessible only after their definition.Freq 3 min read JavaScript Anonymous Functions An anonymous function is simply a function that does not have a name. Unlike named functions, which are declared with a name for easy reference, anonymous functions are usually created for specific tasks and are often assigned to variables or used as arguments for other functions.In JavaScript, you 3 min read JavaScript Function Call The call() method is a predefined JavaScript method. It can be used to invoke (call) a method with an owner object as an argument (parameter). This allows borrowing methods from other objects, executing them within a different context, overriding the default value, and passing arguments. Syntax: cal 2 min read Asynchronous JavaScript Asynchronous JavaScript is a programming approach that enables the non-blocking execution of tasks, allowing concurrent operations, improved responsiveness, and efficient handling of time-consuming operations in web applications, JavaScript is a single-threaded and synchronous language. The code is 2 min read How to chain asynchronous functions in JavaScript ? JavaScript is a single-threaded, asynchronous programming language. Thus, some time-consuming operations like I/O, accessing the database, network calls, etc. are performed asynchronously so that it does not interrupt things in the only JS thread. This can be done by asynchronous code like promises 2 min read Like