Value is generator function

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

Written by Angelos Chalaris

I'm Angelos Chalaris, a JavaScript software engineer, based in Athens, Greece. The best snippets from my coding adventures are published here to help others learn to code.

If you want to keep in touch, follow me on GitHub or Twitter.

More like this

  • JavaScript Generator Functions

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

    Collection · 17 snippets

  • Value is async function

    Checks if the given argument is an async function.

    JavaScript, Type · Oct 20, 2020

  • Value is function

    Checks if the given argument is a function.

    JavaScript, Type · Sep 15, 2020

  • Value is string

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

    JavaScript, Type · Oct 20, 2020