Add isAsyncFunction

This commit is contained in:
Angelos Chalaris
2020-08-07 15:41:55 +03:00
parent 338bce1ed7
commit 166a6f9f70

View File

@ -0,0 +1,18 @@
---
title: isAsyncFunction
tags: type,function,intermediate
---
Checks if the given argument is an `async` function.
Use `Object.prototype.toString()` and `Function.call()` and check if the result is `'[object AsyncFunction]'`.
```js
const isAsyncFunction = val =>
Object.prototype.toString.call(val) === '[object AsyncFunction]';
```
```js
isAsyncFunction(function() {}); // false
isAsyncFunction(async function() {}); // true
```