[Home] >  Function >  Check if a value is a function

Check if a value is a function

JavaScript version

const isFunction = (v) => ['[object Function]', '[object GeneratorFunction]', '[object AsyncFunction]', '[object Promise]'].includes(Object.prototype.toString.call(v));

Examples

isFunction(function () {}); // true
isFunction(function* () {}); // true
isFunction(async function () {}); // true