Checks if a value is a function
This is a type-safe equivalent to typeof x === 'function'.
typeof x === 'function'
If you are using TypeScript and you know the function signature, you can provide the generic T for your guard.
T
The value to check. It can be any value, including static methods, but not getters or setters.
isFn(() => {}); // => trueisFn(Array.isArray); // => trueisFn(function () {}); // => trueisFn(Function); // => trueisFn(HTMLElement); // => true Copy
isFn(() => {}); // => trueisFn(Array.isArray); // => trueisFn(function () {}); // => trueisFn(Function); // => trueisFn(HTMLElement); // => true
Checks if a value is a function
This is a type-safe equivalent to
typeof x === 'function'.If you are using TypeScript and you know the function signature, you can provide the generic
Tfor your guard.