Sometimes, we want to check a function is async with JavaScript.
In this article, we’ll look at how to check a function is async with JavaScript.
How to check a function is async with JavaScript?
To check a function is async with JavaScript, we can check if the function’s constructor is an instance of the constructor that creates an async function.
For instance, we write
const AsyncFunction = (async () => {}).constructor;
console.log(asyncFn instanceof AsyncFunction)
to get the constructor of the async async () => {}
function with the constructor
property.
Then we check if asyncFn
is an instance of the AsyncFunction
constructor with asyncFn instanceof AsyncFunction
.
Conclusion
To check a function is async with JavaScript, we can check if the function’s constructor is an instance of the constructor that creates an async function.