Value is generator function

Angelos Chalaris · JavaScript, Type, Function · Oct 20, 2020

Checks if the given argument is a generator function.

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.

  • Value is async function

    JavaScript, Type

    Checks if the given argument is an async function.

  • Value is function

    JavaScript, Type

    Checks if the given argument is a function.

  • Value is string

    JavaScript, Type

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