jQuery Deferred isRejected() Method

Beginner
⏱️ 9 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
State check

What You’ll Learn

The isRejected() method returns true when a jQuery Deferred has failed — and false while it is still pending or after a successful resolve. This tutorial covers syntax, return values, five examples, comparisons with state(), and when not to poll this method.

01

Syntax

dfd.isRejected()

02

true

Rejected state

03

false

Pending / resolved

04

state()

Modern jQuery 3+

05

vs fail()

Check vs callback

06

Timing

After settle

Introduction

Callbacks like fail() react when a Deferred rejects. Sometimes you need a quick synchronous answer: has this task already failed? isRejected() answers that question with a boolean — no callback registration required.

Use it for conditional debugging, branching in test helpers, or inspecting Deferred state at a known checkpoint. For production error handling, prefer fail() or catch() — they fire automatically when rejection happens, without polling.

Understanding the isRejected() Method

isRejected() is a state query on jQuery’s Deferred object. It returns true only when the Deferred has entered the rejected state via reject(), a failed AJAX call, or a rejected promise in a chain.

It returns false when the Deferred is still pending (work not finished) or resolved (success). A Deferred can only settle once — it never flips from rejected back to resolved.

💡
Beginner Tip

Do not call isRejected() immediately after starting async work — the old reference example checked right after setTimeout was scheduled, which always returned false. Check inside fail() or after reject() runs.

📝 Syntax

General form of deferred.isRejected:

jQuery
deferred.isRejected()

Return value

  • true — the Deferred has been rejected (failed).
  • false — the Deferred is still pending or was resolved successfully.

Modern alternative (jQuery 3+)

jQuery
if (dfd.state() === "rejected") {
  console.log("The operation failed");
}

⚡ Quick Reference

Deferred stateisRejected()state()
Pendingfalse"pending"
Resolvedfalse"resolved"
Rejectedtrue"rejected"

📋 isRejected() vs fail() vs state()

Three ways to interact with rejection — choose based on whether you need a callback or a snapshot.

isRejected()
boolean

Sync state snapshot

fail()
callback

Runs on reject

state()
"rejected"

jQuery 3+ preferred

Timing
after settle

Not while pending

Examples Gallery

Each example shows when isRejected() returns true or false. Use the Try-it links to run them interactively.

📚 Getting Started

See isRejected() return true only after rejection.

Example 1 — After reject()

Reject the Deferred, then check isRejected().

jQuery
const dfd = $.Deferred();

dfd.reject("Network error");

console.log(dfd.isRejected());  // true
console.log(dfd.state());       // "rejected"
Try It Yourself

How It Works

Once reject() runs, the state locks to rejected. Every subsequent isRejected() call returns true.

Example 2 — While Still Pending

Before resolve() or reject(), the Deferred is not rejected.

jQuery
const dfd = $.Deferred();

console.log(dfd.isRejected());  // false
console.log(dfd.state());       // "pending"
Try It Yourself

How It Works

Pending means the async operation has not settled yet. isRejected() is false — the failure has not happened (or has not been recorded yet).

Example 3 — After Successful Resolve

A resolved Deferred is not rejected — both checks return success indicators.

jQuery
const dfd = $.Deferred();

dfd.resolve("OK");

console.log(dfd.isRejected());  // false
console.log(dfd.isResolved());  // true
console.log(dfd.state());       // "resolved"
Try It Yourself

How It Works

Success and failure are mutually exclusive. After resolve, isRejected() stays false forever for that Deferred.

📈 Practical Patterns

Correct timing with async work and modern state() checks.

Example 4 — Delayed Reject (Check Inside fail())

When work finishes later, inspect state in the failure callback — not before the timer fires.

jQuery
const dfd = $.Deferred();

console.log("before timeout:", dfd.isRejected());  // false

setTimeout(function () {
  dfd.reject("Operation timed out");
}, 800);

dfd.fail(function () {
  console.log("in fail():", dfd.isRejected());  // true
  console.log("state():", dfd.state());         // "rejected"
});
Try It Yourself

How It Works

This fixes the timing bug in the original reference example, which called isRejected() synchronously while the timeout was still pending.

Example 5 — Compare with state() === "rejected"

In jQuery 3+, state() is the preferred way to read rejection status.

jQuery
function logStatus(dfd) {
  console.log("state():", dfd.state());
  console.log("isRejected():", dfd.isRejected());
  console.log('state === "rejected":', dfd.state() === "rejected");
}

const failed = $.Deferred().reject("error");
logStatus(failed);

const ok = $.Deferred().resolve("done");
logStatus(ok);
Try It Yourself

How It Works

isRejected() and state() === "rejected" agree on rejected Deferreds. Use state() when you also need to distinguish pending from resolved.

🚀 Use Cases

  • Error state detection — confirm a Deferred failed before running recovery logic.
  • Conditional branching — choose different code paths in tests or debug utilities based on rejection.
  • Dynamic UI updates — show error panels when state() is "rejected" after async UI loads.
  • Logging — record rejection status alongside other Deferred metadata during diagnostics.
  • Multi-task coordination — inspect individual Deferreds returned from $.when() after a batch completes.

🧠 When isRejected() Returns What

1

Pending

Work in progress — isRejected() is false.

Wait
2

Settled

Deferred resolves or rejects — state locks permanently.

Final
3

Query

isRejected() returns true only for the rejected branch.

Check
=

Informed action

Combine with fail() for reactions and state() for readable status in jQuery 3+.

📝 Notes

  • isRejected() is deprecated in jQuery 3.0+ — use state() === "rejected" in new code.
  • Never assume false means success — it can also mean still pending.
  • Prefer fail() over polling isRejected() in production error handling.
  • isRejected() and isResolved() are never both true on the same Deferred.
  • For jqXHR from $.ajax(), the same state rules apply once the request completes.

Browser Support

deferred.isRejected() has been available since jQuery 1.5. It remains supported in jQuery 3.x but is deprecated — prefer state().

jQuery 1.5+

jQuery Deferred.isRejected()

Works in jQuery 1.5+, 2.x, and 3.x wherever Deferred objects run. Deprecated since jQuery 3.0 in favor of state().

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
deferred.isRejected() Universal

Bottom line: Safe in legacy jQuery codebases. For new jQuery 3+ projects, write dfd.state() === "rejected" instead.

🎉 Conclusion

The deferred.isRejected() method tells you whether a Deferred has failed. Use it for synchronous state checks at the right moment — after rejection or inside fail() — and prefer state() in modern jQuery code.

Next, explore isResolved() for the success counterpart, or review state() for a single API that covers all three statuses.

💡 Best Practices

✅ Do

  • Check after reject() or inside fail()
  • Use state() in jQuery 3+ projects
  • Pair state checks with proper error callbacks
  • Test pending, resolved, and rejected paths
  • Log state during debugging sessions

❌ Don’t

  • Poll isRejected() in a busy loop
  • Check immediately after starting async work
  • Assume false means success
  • Rely on isRejected alone for user-facing errors
  • Ignore deprecation — migrate to state()

Key Takeaways

Knowledge Unlocked

Five things to remember about isRejected()

How to read rejection state on a Deferred.

5
Core concepts
T 02

true

Rejected

Failed
F 03

false

Pending / OK

Other
04

Timing

After settle

Critical
state 05

Modern

Prefer state()

jQ 3+

❓ Frequently Asked Questions

isRejected() returns true when the Deferred has been rejected (failed). It returns false while the Deferred is still pending or after it has been resolved successfully.
Only after the Deferred may have settled — inside a fail() callback, after reject(), or when you know async work finished. Calling it immediately while a timer or AJAX request is still pending always returns false.
In jQuery 3.0+, isRejected() and isResolved() are deprecated in favor of state(), which returns "pending", "resolved", or "rejected". Both still work; prefer dfd.state() === "rejected" in new code.
fail() registers a callback that runs when rejection happens. isRejected() is a synchronous boolean check of current state — it does not register a listener.
No. Once resolved or rejected, the state is locked. isRejected() is true only for the rejected state; isResolved() is true only for the resolved state.
Usually no. Prefer fail(), catch(), or always() callbacks. Polling isRejected() in a tight loop wastes CPU; use callbacks or state() checks at known checkpoints instead.
Did you know?

jQuery added state() in version 1.7 as a single way to read "pending", "resolved", or "rejected". In jQuery 3.0, isRejected() and isResolved() were deprecated because state() covers every case in one call.

Continue to isResolved()

Learn the success-side counterpart to isRejected().

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