jQuery jQuery.isFunction() Method

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Callback test

What You’ll Learn

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

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.

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.

📝 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();
  }
}

⚡ Quick Reference

Value$.isFunction()
function () {}true
() => {}true
async function () {}true
jQuery / $true
"text"false
{} / []false
$("div")false (jQuery object)

📋 $.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

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.

jQuery
console.log($.isFunction(function () {})); // true
console.log($.isFunction("text"));           // false
Try It Yourself

How It Works

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
Try It Yourself

How It Works

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
Try It Yourself

How It Works

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
Try It Yourself

How It Works

An object that contains a function property is still an object. Use $.isFunction(obj.run) to test the method itself, not the container.

Example 5 — jQuery-Style Plugin Overload (Function or Selector)

Route the first argument like jQuery does for $(fn) vs $(selector).

jQuery
function myPlugin(arg) {
  if ($.isFunction(arg)) {
    return arg();              // ready-style callback
  }
  return $(arg);               // assume selector string
}

console.log(typeof myPlugin(function () { return "cb"; }));
console.log(myPlugin("#app") instanceof jQuery);
Try It Yourself

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.

🚀 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.
  • AJAX helpers — validate success / error parameters.
  • Legacy jQuery code — consistent function detection across old IE builds.

🧠 How jQuery.isFunction() Classifies a Value

1

Receive value

Any JavaScript value is passed to $.isFunction(obj).

Input
2

Run type check

jQuery delegates to the same logic as $.type — internal class tag mapping.

type
3

Match function

If the resolved type string is "function", return true.

Compare
4

Return boolean

Otherwise return false. No exception for null or undefined.

📝 Notes

  • Available since jQuery 1.2.
  • Equivalent to jQuery.type(obj) === "function".
  • Does not treat objects with a call method as functions unless they are function objects.
  • The jQuery factory $ itself is a function — $.isFunction(jQuery) is true.
  • Safe on null and undefined — returns false, does not throw.
  • Related: $.type(), $.isArray(), $.isPlainObject().

Browser Support

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 Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All 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.

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.

💡 Best Practices

✅ Do

  • Guard with $.isFunction(fn) before fn()
  • Use for plugin callback and overload routing
  • 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

Key Takeaways

Knowledge Unlocked

Five things to remember about jQuery.isFunction()

Validate callbacks the jQuery way.

5
Core concepts
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.

Continue to jQuery.isNumeric()

Test finite numbers and numeric strings before parsing user input.

isNumeric() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful