isGeneratorFunction

JavaScript, Type, Function

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

Recommended snippets & collections

  • JavaScript generator functions are a more advanced yet very powerful JavaScript ES6 feature, which you can start using in your code right now.

  • isAsyncFunction

    JavaScript, Type

    Checks if the given argument is an async function.

  • isFunction

    JavaScript, Type

    Checks if the given argument is a function.

  • isString

    JavaScript, Type

    Checks if the given argument is a string. Only works for string primitives.