_.isFunction(a) vs. typeof a === 'function'? javascript

Kosmetika picture Kosmetika · Jun 14, 2013 · Viewed 60.2k times · Source

I think it might be only performance case - http://jsperf.com/comparing-underscore-js-isfunction-with-typeof-function/2

And seems that typeof is faster.. so my question is - which is more appropriate to use?

Answer

Denys Séguret picture Denys Séguret · Jun 14, 2013

There is no reason not to use typeof.

Not only is it faster but the ECMAScript specification ensures that all functions have a type of "function" and that only functions can have a type of "function" :

enter image description here

This operator was specifically designed to get the type of a value, so why not use it ?