I have always used (typeof variable === "function") and I stumbled across jQuery.isFunction() and I was wondering:
- What is the difference between the typeof method and jQuery’s method? And not only what the difference is, but
- When is it appropriate to use the typeof method and when is it appropriate to use jQuery’s method?
There is almost no difference, other than that using jQuery is slightly slower. See the source code:
which calls a function which calls another function to determine the exact same thing as what you showed 😛
There is literally no advantage to jQuery in this case [or for that manner, 90% of the use-cases of the library]. Look into Vanilla-JS and check out some of its features 😛
TLDR: Don’t use jQuery for this…or anything.
UPDATE
Here’s a benchmark showing you that Vanilla JS is roughly 93% faster than jQuery: http://jsperf.com/jquery-isfunction-vs-vanilla-is-function.