# Function.isFunction

**URL:** <https://es.discourse.group/t/function-isfunction/385>\
**Category:** 💡 Ideas\
**Created:** [July 2, 2020, 9:19pm UTC](https://es.discourse.group/t/function-isfunction/385 "2020-07-02T21:19:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike-Neto](https://avatars.discourse-cdn.com/v4/letter/m/90ced4/32.png) [@Mike-Neto](https://es.discourse.group/u/Mike-Neto)\
**Post date:** [July 2, 2020, 9:19pm UTC](https://es.discourse.group/t/function-isfunction/385/1 "2020-07-02T21:19:18Z")

</div>

Similar in nature to Array.isArray.  
I just found it odd that there is no simple way to do this and there are a bunch of implementations if it.

The basic intent is that:

```javascript
if (Function.isFunction(x)) {
  x();
}

```

Would never throw any errors.

Current implementations:

> <https://github.com/lodash/lodash/blob/ddfd9b11a0126db2302cb70ec9973b66baec0975/lodash.js#L11647>

  
[https://api.jquery.com/jQuery.isFunction/](https://api.jquery.com/jQuery.isFunction/) which was deprecated and recommended to use typeof x === "function"

---

<div class="post-metadata">

**Author:** ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)\
**Post date:** [July 2, 2020, 9:32pm UTC](https://es.discourse.group/t/function-isfunction/385/2 "2020-07-02T21:32:11Z")

</div>

`typeof x === 'function'` already achieves this, with syntax, so it's impossible for it to break (`delete Function.isFunction`, for example, would break your suggestion).

The more complex logic you see in lodash, and in [https://npmjs.com/is-callable](https://npmjs.com/is-callable) is for older non spec-compliant engines.

---

<div class="post-metadata">

**Author:** ![claudiameadows](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/claudiameadows/32/126_2.png) [@claudiameadows](https://es.discourse.group/u/claudiameadows)\
**Post date:** [July 10, 2020, 5:10am UTC](https://es.discourse.group/t/function-isfunction/385/3 "2020-07-10T05:10:03Z")

</div>

And just to add onto that, there's an existing (withdrawn) proposal that looked into rounding out that matrix: [http://github.com/jasnell/proposal-istypes](http://github.com/jasnell/proposal-istypes)

You may want to look into its history, as [this commit](https://github.com/jasnell/proposal-istypes/commit/b468848a65f20fdf4473df293295d2ebc443d013) went from `Foo.isFoo(value)` to `Builtins.is(Foo, value)`. Also, [it was only talked about once in meetings](https://github.com/tc39/notes/blob/7b2de881081abd34b02bc87bcdb662fd97555795/meetings/2017-09/sept-28.md#14ia-builtinstypeof-and-builtinsis) and was withdrawn in favor of `Object.prototype.toString` as that generally worked for 99% of cases.
