Node.js util.types.isAsyncFunction() Method
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 a single parameter as mentioned above and described below:
- value: It is a required parameter that holds any data type.
Return Value: It returns a boolean value, TRUE if the value is an async function from the perspective of the JavaScript engine, FALSE otherwise.
The below examples illustrate the use of util.types.isAsyncFunction() method in Node.js:
Example 1:
javascript
const util = require( 'util' );
let f2 = async function function2() { }
let f1 = function function1() { }
console.log(util.types.isAsyncFunction(f2));
console.log(util.types.isAsyncFunction(f1));
|
Output:
true
false
Example 2:
javascript
const util = require( 'util' );
const f2 = async function function2() { }
const f1 = function function1() { }
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
Last Updated :
03 Apr, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...