jQuery noop() Method

Beginner
5 min read
Updated: Oct 2026
5 examples
Live preview

What Is jQuery.noop()?

jQuery.noop (alias $.noop) is a shared empty function that does nothing when called (since jQuery 1.4). Official use: pass it around when an API wants a function but you have no work to do.

Remember
$.noop          → function () {}   (shared reference)
$.noop()        → undefined        (call does nothing)

// Plugin default pattern:
var onComplete = options.onComplete || $.noop;
onComplete();   // always safe to call
NeedUse
Optional callback defaultoptions.fn || $.noop
Test if value is a function$.isFunction(fn)
Bind this for a callback$.proxy(fn, context)

How to Use jQuery.noop()

Treat $.noop as a reusable “do nothing” callback.

  1. When a callback is optional, default it: var cb = options.cb || $.noop.
  2. Call cb(...) without an if (cb) guard.
  3. Pass $.noop (the reference) into APIs that require a function.
  4. Remember: $.noop() returns undefined and ignores arguments.
PieceRequired?Role
ArgumentsNoneAccepts any; all ignored
Call return—undefined
Reference—$.noop — shared empty function

Pseudocode

Pseudocode
noop = function ():
    // intentionally empty
    return undefined

// Official idea for plugins:
callback = userCallback or noop
callback(result)   // never throws for "missing" callback

Cheat Sheet

Keep these facts handy for optional callbacks.

TopicDetail
AccessjQuery.noop / $.noop
SincejQuery 1.4
Call resultundefined
Shared?Yes — one function object
vs function(){}New object each time you write it
Best forDefault / optional callbacks

Live Preview

Inspect $.noop, call it, or compare it with a fresh empty function.

Browser demo of $.noop — same idea as the examples below.

Result
typeof $.noop → "function"
$.noop() → undefined

jQuery Examples

Short, copy-ready snippets. Open DevTools Console, or use Try It Yourself for a live editor.

Example 1 — Call the Empty Function

Confirm type, return value, and that arguments are ignored.

jQuery
var empty = $.noop;

console.log(typeof empty);           // "function"
console.log(empty());                // undefined
console.log(empty(1, 2, "test"));    // undefined
Try It Yourself

How It Works

  1. Reference. $.noop is a real function object.
  2. Call. Invoking it runs an empty body → undefined.
  3. Args ignored. Extra arguments do not change the result.
  4. Safe. Always callable — never throws for “missing” work.

Example 2 — Optional Callback Default

Official plugin idea: fall back to $.noop when no callback is given.

jQuery
function doWork(userCallback) {
  var callback = userCallback || $.noop;
  callback("done");
}

doWork();                              // silent (noop)
console.log("no callback: ok");

doWork(function (msg) {
  console.log("with callback: " + msg); // "with callback: done"
});
Try It Yourself

How It Works

  1. Default. Missing callback becomes $.noop.
  2. Always call. One callback(...) line covers both cases.
  3. No branch. You avoid if (userCallback) at the call site.
  4. User fn. When provided, the real callback runs instead.

Example 3 — Plugin Option Defaults

Seed lifecycle hooks with $.noop via $.extend.

jQuery
function myWidget(el, options) {
  var opts = $.extend({}, {
    onInit: $.noop,
    onDestroy: $.noop
  }, options);

  opts.onInit(el);
  return {
    destroy: function () { opts.onDestroy(el); }
  };
}

var w = myWidget(document.body);
w.destroy(); // safe with defaults
Try It Yourself

How It Works

  1. Defaults. onInit / onDestroy start as $.noop.
  2. Extend. User options can override those hooks.
  3. Call freely. Init and destroy always invoke a function.
  4. No errors. Omitting options still works.

Example 4 — Shared Reference vs New Functions

$.noop is always the same object; function(){} is not.

jQuery
var a = $.noop;
var b = $.noop;
var c = function () {};
var d = function () {};

console.log(a === b); // true  — shared
console.log(c === d); // false — new each time
Try It Yourself

How It Works

  1. Same ref. Every read of $.noop returns one shared function.
  2. New literals. Each function () {} creates a distinct object.
  3. Identity. === proves the difference.
  4. Why it helps. Defaults stay stable and cheap to assign.

Example 5 — Valid Event Handler

$.noop is a real function — fine for .on() and $.isFunction.

jQuery
$("#btn").on("click", $.noop);

console.log($.isFunction($.noop)); // true
// Clicking the button runs the empty handler silently
Try It Yourself

How It Works

  1. Pass reference. .on("click", $.noop) registers the empty function.
  2. isFunction. $.isFunction($.noop) is true.
  3. Click. The handler runs and does nothing — no error.
  4. Use case. Handy stub while wiring events or disabling a hook temporarily.

Edge Cases & Pitfalls

Check these before using $.noop as a default callback.

call

Do not pass $.noop() as the callback

$.noop() is undefined. Pass $.noop (no parentheses) when an API needs a function.

return

Always returns undefined

If a callback must return a value (for example false to cancel), noop is the wrong default — supply a function that returns what you need.

shared

One shared function object

Do not attach custom properties to $.noop expecting isolation — every caller sees the same function.

vs proxy

Need a bound this? Use $.proxy

noop only fills “no work.” For context binding, use $.proxy().

Browser Support

jQuery.noop needs jQuery loaded. It has been available since jQuery 1.4+ in all browsers your jQuery build supports.

✓ jQuery 1.4+ · Browsers

jQuery.noop()

Works in Chrome, Firefox, Safari, Edge, and other browsers with jQuery loaded. Use the shared empty function as a safe default callback.

100% Browser support
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
$.noop Browsers

Bottom line: Pass $.noop for optional callbacks; calling it returns undefined and does nothing.

Performance Notes

ApproachCostBest for
$.noopO(1), sharedDefault / optional callbacks
function () {}New object each timeOne-off anonymous handlers
if (fn) fn()Branch each callWhen you prefer explicit guards

Prefer $.noop for stable defaults. The win is clarity and fewer branches, not micro-optimizing empty calls.

Key Takeaways

  • Role: $.noop is a shared empty function.
  • Pass the ref: use $.noop, not $.noop(), as a callback.
  • Defaults: options.fn || $.noop then always call.
  • Call result: always undefined; args ignored.

One line: $.noop is jQuery’s shared empty function — the standard default when a callback is optional.

Frequently Asked Questions

jQuery.noop is a shared empty function — a function that does nothing when called. Added in jQuery 1.4. You typically pass the reference $.noop as a callback; calling $.noop() returns undefined.
Calling $.noop() returns undefined because the function body is empty. The useful part is the function reference itself — store $.noop and pass it where a callback is required.
Both run no code, but $.noop is the same function object every time. Writing function() {} creates a new function object on each expression. For default callbacks, $.noop is clearer and slightly cheaper.
Use it as the default when optional callbacks are omitted: var onComplete = options.onComplete || $.noop; Then call onComplete() safely without checking if (onComplete) every time.
Yes. $.noop is a real function, so $.isFunction($.noop) is true. That makes it safe anywhere a callback function is expected.
Yes. The empty function ignores all arguments — calling $.noop(1, 2, 3) still does nothing and returns undefined. APIs that pass event objects or data to callbacks work fine with noop.

Next: jQuery.escapeSelector()

Escape special characters so dynamic class and ID selectors stay safe.

escapeSelector() →

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.

8 people found this page helpful