jQuery Deferred reject() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Deferred

Definition

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.

Syntax

Start with these common calls. Keep them short and readable.

jQuery
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
CallWhat it does
argsValues passed to every fail callback
ReturnSame Deferred (chainable)
SincejQuery 1.5

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Create a Deferred (keep it private in your helper).
Step 2Attach fail() / then() (or return promise() for callers).
Step 3On failure, call reject(args…) with a useful reason.

Return Value

Return ValueDescription
Value / undefinedGetters usually return a value from the first matched element, or undefined when nothing applies.

jQuery Examples

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.

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.

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".

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() Method

Reject with a custom this context and an arguments array.

deferred.rejectWith() Method tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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