Files
30-seconds-of-code/javascript/snippets/is-generator-function.md
2023-05-01 22:35:56 +03:00

560 B

title, type, tags, author, cover, dateModified
title type tags author cover dateModified
Value is generator function snippet
type
function
chalarangelo interior-4 2020-10-20T11:21:07+03:00

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]'.
const isGeneratorFunction = val =>
  Object.prototype.toString.call(val) === '[object GeneratorFunction]';
isGeneratorFunction(function() {}); // false
isGeneratorFunction(function*() {}); // true