Files
30-seconds-of-code/snippets/isGeneratorFunction.md
Isabelle Viktoria Maciohsek c3a2e47672 Add prototype to descriptions
2020-10-20 11:21:07 +03:00

19 lines
470 B
Markdown

---
title: isGeneratorFunction
tags: type,function,intermediate
---
Checks if the given argument is a generator function.
- Use `Object.prototype.toString()` and `Function.prototype.call()` and check if the result is `'[object GeneratorFunction]'`.
```js
const isGeneratorFunction = val =>
Object.prototype.toString.call(val) === '[object GeneratorFunction]';
```
```js
isGeneratorFunction(function() {}); // false
isGeneratorFunction(function*() {}); // true
```