jQuery Deferred reject() Method

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

What Is reject()?

deferred.reject([args]) settles a Deferred as rejected (since jQuery 1.5) and runs fail callbacks from fail() or then(). Optional args are passed to those handlers. It returns the same Deferred for chaining.

Remember
deferred.reject([args…])

reject()  → settle as failed (owner only)
fail()    → listen for rejection
resolve() → settle as success (opposite)

state locks after reject — once only
return promise() so callers cannot reject
NeedUse
Signal failuredfd.reject(reason)
Listen for failuredfd.fail(fn)
Custom this + args arraydfd.rejectWith(ctx, args)

How to Use reject()

Own the Deferred; reject when the work fails; let others listen.

  1. Create a Deferred (keep it private in your helper).
  2. Attach fail() / then() (or return promise() for callers).
  3. On failure, call reject(args…) with a useful reason.
  4. Do not call resolve() afterward — the Deferred is already settled.
PieceRequired?Role
argsOptionalValues passed to every fail callback
Return—Same Deferred (chainable)
Since—jQuery 1.5

Pseudocode

Pseudocode
dfd = Deferred
handlers = fail callbacks (from fail / then)

reject(args…):
    if dfd already settled: return  // ignore
    state = "rejected"
    remember args
    for each fail handler (in add order):
        handler(args…)

later fail(fn):
    if already rejected: fn(args…) immediately
    else: queue fn

Cheat Sheet

Keep these facts handy when signaling async failure.

TopicDetail
Syntaxdeferred.reject([args…])
Triggersfail(), rejection branch of then(), always()
State"rejected" — settles once
Late fail()Runs immediately with the reject args
vs fail()reject fires; fail listens
vs resolve()Failure vs success settlement
SincejQuery 1.5

Live Preview

See how reject() drives fail() and once-only settlement.

Browser demo of deferred.reject — same idea as the examples below.

Result
fail → Network timeout
state → rejected

/* reject() settles; fail() listens */

jQuery Examples

Short, copy-ready snippets. Open the browser console, or use Try It Yourself for a live editor.

Example 1 — reject() + fail()

Settle as failed and read the reason in a fail handler.

jQuery
var dfd = $.Deferred();

dfd.fail(function (reason) {
  console.log(reason);  // Network timeout
});

dfd.reject("Network timeout");
Try It Yourself

How It Works

  1. Register fail. The handler waits for rejection.
  2. Call reject. Pass a clear string reason.
  3. Handler runs. It receives that same string.
  4. State locks. The Deferred is now "rejected".

Example 2 — Multiple Reject Arguments

Pass several values; every fail callback receives them in order.

jQuery
var dfd = $.Deferred();

dfd.fail(function (code, message) {
  console.log(code + ": " + message);  // 404: Not found
});

dfd.reject(404, "Not found");
Try It Yourself

How It Works

  1. Plan the shape. Fail handlers expect (code, message).
  2. Reject with two args. reject(404, "Not found").
  3. Receive both. The callback logs them together.
  4. Keep it consistent. Use the same arg order everywhere you reject.

Example 3 — Late fail() After Reject

Handlers added after rejection run immediately with the reject args.

jQuery
var dfd = $.Deferred();

dfd.reject("already failed");

dfd.fail(function (reason) {
  console.log(reason);  // already failed
});
Try It Yourself

How It Works

  1. Reject first. State becomes rejected; args are stored.
  2. Attach fail late. Official rule: it runs immediately.
  3. Same args. You still get "already failed".
  4. Useful for UI. Late listeners still see the final error.

Example 4 — Settle Once (Reject After Resolve Ignored)

After resolve(), a later reject() does nothing.

jQuery
var dfd = $.Deferred();
var lines = [];

dfd.done(function (v) { lines.push("done: " + v); });
dfd.fail(function (v) { lines.push("fail: " + v); });

dfd.resolve("ok");
dfd.reject("nope");  // ignored

console.log(lines.join(" | "));  // done: ok
console.log(dfd.state());         // resolved
Try It Yourself

How It Works

  1. Attach both paths. done and fail are ready.
  2. Resolve first. State becomes "resolved"; done runs.
  3. Reject later. Ignored — fail never runs.
  4. Rule. First settle wins; the other is a no-op.

Example 5 — Reject Behind promise()

Only the owner rejects; callers listen on the returned Promise.

jQuery
function loadFile(ok) {
  var dfd = $.Deferred();
  setTimeout(function () {
    if (ok) dfd.resolve("file.txt");
    else dfd.reject("missing file");
  }, 200);
  return dfd.promise();
}

loadFile(false).fail(function (err) {
  console.log(err);  // missing file
});
Try It Yourself

How It Works

  1. Private Deferred. Only loadFile can call reject.
  2. Return Promise. Callers get promise(), not settle methods.
  3. Fail path. ok is false → reject("missing file").
  4. Listen outside. fail on the Promise prints the error.

Edge Cases & Pitfalls

Check these before relying on reject() in real projects.

once

Settles only once

After resolve or reject, further settle calls are ignored. Check state() if you need to know which won.

owner

Only the owner should reject

Official guidance: return promise() so other code cannot change state with reject().

args

Pass useful error info

Empty reject() works but hurts debugging. Prefer a message, code, or Error-like object.

context

Need a custom this?

Use rejectWith(context, args) when fail handlers rely on a specific this.

Browser Support

deferred.reject() needs jQuery 1.5+ loaded. It works across jQuery 1.5–3.x as the standard way to settle a Deferred as failed.

✓ jQuery 1.5+

deferred.reject()

Works in Chrome, Firefox, Safari, and Edge when jQuery 1.5+ is loaded. Pair with fail() or then() to handle the rejection.

100% With jQuery 1.5+
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
reject() Universal

Bottom line: Safe wherever jQuery Deferreds exist. Keep reject() private; expose promise() to callers.

Performance Notes

ApproachCostBest for
reject(args)O(handlers)Normal failure settlement
Many fail handlersEach runs onceKeep handlers small
Reject after settleNo-opHarmless but wasteful — avoid

Rejection cost is dominated by your fail handlers (UI updates, logging), not by reject() itself. Pass compact error values, not huge objects, unless needed.

Key Takeaways

  • Role: settle a Deferred as failed and run fail callbacks.
  • Pair: reject fires; fail / then listen.
  • Once: after settle, later reject/resolve are ignored.
  • Safety: return promise() so callers cannot reject.

One line: reject(args) marks failure — keep it private, pass clear reasons, listen with fail().

Frequently Asked Questions

reject() settles the Deferred as failed and runs failCallbacks from fail() or then(). Optional args are passed to those handlers. The state becomes rejected and stays locked.
reject() is called by the Deferred owner to signal failure. fail() registers a listener that runs when rejection happens. reject fires; fail listens.
No. A Deferred settles once. After resolve(), later reject() is ignored. After reject(), later resolve() is ignored.
Any values — a string, Error, status code, or multiple arguments. Each fail callback receives the same args from the reject() call.
Late fail() handlers run immediately with the arguments that were passed to reject() — same idea as late done() after resolve().
Usually no. Keep the Deferred private and return promise() so outside code can attach fail/done but cannot settle the operation.

Next: deferred.rejectWith()

Reject with a custom this context and an arguments array.

rejectWith() 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.

9 people found this page helpful