The jQuery.isFunction() utility returns true when a value is a callable JavaScript function. This tutorial covers syntax, five worked examples for callback validation, comparisons with typeof and $.type(), and safe patterns before invoking user-supplied handlers.
01
Syntax
$.isFunction(obj)
02
Boolean
true / false
03
fn yes
Callables
04
string no
Non-functions
05
Arrow
Modern fn
06
Guard
Before call
Fundamentals
Introduction
jQuery plugins and event helpers often accept optional callbacks — a function to run when work completes, or a string selector when the argument is not callable. Before you invoke callback(), you must confirm the value really is a function.
jQuery provides jQuery.isFunction() (also written $.isFunction()) as a reliable boolean test. It returns true for function declarations, expressions, arrows, async functions, and methods — and false for strings, objects, arrays, and other types.
Concept
Understanding the jQuery.isFunction() Method
jQuery.isFunction(obj) is equivalent to jQuery.type(obj) === "function". jQuery inspects the internal class tag of the value and maps it to the familiar type name "function".
Use it anywhere a parameter might be a callback: plugin hooks, AJAX complete handlers, custom event emitters, and utility wrappers that mirror jQuery’s own overloaded arguments.
💡
Beginner Tip
Always guard before calling: if ($.isFunction(fn)) { fn(); }. Strings that look like code are not functions — "alert(1)" returns false.
Foundation
📝 Syntax
General form of jQuery.isFunction:
jQuery
jQuery.isFunction( obj )
// or
$.isFunction( obj )
Parameters
obj — any JavaScript value to test.
Return value
true if obj is a function.
false for all other types.
Minimal workflow
jQuery
function runIfCallable(maybeFn) {
if ($.isFunction(maybeFn)) {
maybeFn();
}
}
Cheat Sheet
⚡ Quick Reference
Value
$.isFunction()
function () {}
true
() => {}
true
async function () {}
true
jQuery / $
true
"text"
false
{} / []
false
$("div")
false (jQuery object)
Compare
📋 $.isFunction vs typeof vs $.type
Three ways to detect functions — pick based on consistency needs.
$.isFunction
true / false
jQuery boolean; matches $.type
typeof
"function"
Native operator; same for normal fn
$.type
"function"
String when branching many types
callable
typeof only
Neither detects plain callable objects
Hands-On
Examples Gallery
Each example uses $.isFunction(). Open DevTools or use the Try-it links to run them interactively.
📚 Getting Started
The official jQuery API demo — functions pass, strings fail.
Example 1 — Function vs Non-Function
The canonical check from the jQuery documentation.
Anonymous functions, named functions, and methods all return true. Primitive strings and other non-callable values return false — even if the string contains JavaScript source code.
📈 Practical Patterns
Safe invocation, modern function forms, comparisons, and plugin overloads.
Example 2 — Invoke a Callback Only When It Is a Function
Prevent runtime errors when an optional handler is omitted or wrong type.
jQuery
function notify(done, message) {
if ($.isFunction(done)) {
done(message);
}
}
notify(function (msg) { console.log(msg); }, "Saved");
notify(null, "Ignored"); // no error
The guard pattern appears throughout jQuery internals: call user code only after confirming it is callable. Passing null or omitting the argument skips the branch safely.
Example 3 — Arrow Functions and Async Functions
Modern function syntax is still detected as a function.
jQuery
var arrow = function (x) { return x * 2; };
var asyncFn = async function () { return 1; };
console.log($.isFunction(arrow)); // true
console.log($.isFunction(asyncFn)); // true
All standard JavaScript function object forms pass the test. You do not need separate checks for arrows or async — if it is a function object, $.isFunction returns true.
Example 4 — Compare $.isFunction, typeof, and $.type
On normal functions, all three agree; choose based on API style.
jQuery
var fn = function () { return 42; };
console.log($.isFunction(fn)); // true
console.log(typeof fn === "function"); // true
console.log($.type(fn) === "function"); // true
console.log($.isFunction({ run: fn })); // false — object, not function
string ("cb")
true (jQuery object when #app exists)
How It Works
jQuery’s own constructor overload uses this pattern: if the first argument is a function, treat it as a DOM-ready callback; otherwise parse it as a selector. $.isFunction is the type gate.
Applications
🚀 Common Use Cases
Optional callbacks — invoke completion handlers only when provided.
Plugin methods — accept function hooks in options objects.
Event emitters — verify listener before .call() or .apply().
Argument overloading — distinguish callback vs selector vs config object.
jQuery.isFunction() has been part of jQuery since jQuery 1.2+. It works wherever jQuery runs — all modern browsers and legacy IE when paired with a supported jQuery build.
✓ jQuery 1.2+
jQuery jQuery.isFunction()
Supported in jQuery 1.x, 2.x, and 3.x. Behavior aligns with $.type function detection.
100%With jQuery loaded
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
jQuery.isFunction()Universal
Bottom line: Safe in any project that already includes jQuery. Without jQuery, use typeof fn === "function" for the same boolean result on normal functions.
Wrap Up
Conclusion
The jQuery.isFunction() utility is the jQuery way to confirm a value is callable before you invoke it. It supports every standard function form and integrates cleanly with plugin overload patterns modeled on jQuery() itself.
Guard optional callbacks with if ($.isFunction(fn)), pair with $.type when branching on multiple types, then explore jQuery.isNumeric() for finite number validation.
Test the method property: $.isFunction(obj.handler)
Combine with $.isPlainObject for multi-type args
Prefer typeof fn === "function" in jQuery-free code
❌ Don’t
Call values without checking — may throw on null
Assume string code is executable — it is not a function
Confuse jQuery objects with functions
Use isFunction to detect class instances with methods
Eval strings instead of requiring real function references
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about jQuery.isFunction()
Validate callbacks the jQuery way.
5
Core concepts
⚙01
$.isFunction
Boolean test
API
✅02
fn yes
Callables
Pass
🚫03
string no
Not callable
Fail
🔒04
Guard
Before ()
Pattern
📄05
vs type
Bool vs str
Compare
❓ Frequently Asked Questions
jQuery.isFunction(obj) returns true when obj is a JavaScript function, and false otherwise. It is the boolean shortcut for jQuery.type(obj) === "function".
For normal functions, typeof fn === "function" and $.isFunction(fn) both return true. jQuery.isFunction uses the same internal type detection as $.type(), giving consistent results across browsers in older jQuery codebases.
Yes. Arrow functions, async functions, generator functions, and classic function declarations/expressions all return true from $.isFunction() because they are function objects.
No. A jQuery object like $("div") is not a function — $.isFunction($("div")) returns false. The jQuery factory $ itself is a function.
jQuery.type(value) returns the string "function" for functions. jQuery.isFunction(value) returns true for the same values. Use isFunction when you only need a boolean before calling a callback.
In plugin code and event helpers when a parameter might be a callback or something else — e.g. if ($.isFunction(done)) { done(); }. Prevents runtime errors from calling non-functions.
Did you know?
When you write $(function () { ... }), jQuery internally checks whether the first argument is a function — the same idea as $.isFunction. That overload is why passing a selector string and passing a ready callback use one entry point, and why plugins copied the pattern for their own APIs.