Skip to content
Related Articles
Open in App
Not now

Related Articles

Node.js util.types.isAsyncFunction() Method

Improve Article
Save Article
  • Last Updated : 10 Dec, 2021
Improve Article
Save Article

The util.types.isAsyncFunction() method is an inbuilt application programming interface of the util module which is used to type check for asynchronous functions in the node.js.
Syntax: 

util.types.isAsyncFunction( value )

Parameters: This method accepts single parameter as mentioned above and described below: 

  • value: It is a required parameter that holds any datatype.

Return Value: It returns a boolean value, TRUE if the value is an async function from the perspective of the JavaScript engine, FALSE otherwise.
Below examples illustrate the use of util.types.isAsyncFunction() method in Node.js:
Example 1: 

javascript




// Node.js program to demonstrate the  
// util.types.isAsyncFunction() Method
 
// Allocating util module
const util = require('util');
  
// Functions to be passed as parameter of
// util.types.isAsyncFunction() method
var f2 = async function function2(){}
var f1 = function function1(){}
  
// Printing the returned value from
// util.types.isAsyncFunction() method
console.log(util.types.isAsyncFunction(f2));
console.log(util.types.isAsyncFunction(f1));


Output: 

true
false

Example 2: 

javascript




// Node.js program to demonstrate the  
// util.types.isAsyncFunction() Method
 
// Allocating util module
const util = require('util');
 
// Functions to be passed as parameter
var f2 = async function function2() { }
var f1 = function function1() { }
 
// Calling util.types.isAsyncFunction() method
if (util.types.isAsyncFunction(f2))
    console.log("The passed value is an Async function.");
else
    console.log("The passed value is not an Async function");
 
if (util.types.isAsyncFunction(f1))
    console.log("The passed value is an Async function.");
else
    console.log("The passed value is not an Async function");


Output: 

The passed value is an Async function.
The passed value is not an Async function

Note: The above program will compile and run by using the node filename.js command.
Reference: https://nodejs.org/api/util.html#util_util_types_isasyncfunction_value


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!