Home jQuery Deferred isRejected() jQuery Deferred isRejected() Method Definition deferred.isRejected() was a boolean check: true after reject() / rejectWith(), otherwise false. It took no arguments. Today, use state() instead.
Syntax Start with these common calls. Keep them short and readable.
// OLD (jQuery 1.5–1.7 only — removed in 1.8)
dfd.isRejected() → true | false
// MODERN replacement
dfd.state() === "rejected"
state(): "pending" | "resolved" | "rejected" Call What it does deferred.isRejected()Learn jQuery deferred.isRejected(): check if a Deferred was rejected, why it was removed, use state() === \
Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.
Parameters Parameter Description Step 1 Create or receive a Deferred / Promise. Step 2 Call dfd.state() at a checkpoint (after reject, or inside fail). Step 3 Compare with === "rejected" for the old isRejected() meaning.
Return Value Return Value Description See examples Check the examples below for what this API returns in common cases.
jQuery Examples 1. Example 1 — After reject() 2. Example 2 — Still Pending 3. Example 3 — After resolve() Example 1 — After reject() Once rejected, the modern check returns true.
var dfd = $.Deferred();
dfd.reject("Network error");
var isRejected = dfd.state() === "rejected";
console.log(dfd.state()); // "rejected"
console.log(isRejected); // true How It Works Create a pending Deferred.Reject with a reason — state becomes "rejected".Compare state() === "rejected" (old isRejected()).Example 2 — Still Pending Before settle, the check is false.
var dfd = $.Deferred();
console.log(dfd.state()); // "pending"
console.log(dfd.state() === "rejected"); // false How It Works Fresh Deferred starts as "pending".No reject yet — nothing has failed.Check === "rejected" → false.Example 3 — After resolve() Success is not rejection — the check stays false.
var dfd = $.Deferred();
dfd.resolve("ok");
console.log(dfd.state()); // "resolved"
console.log(dfd.state() === "rejected"); // false How It Works Resolve settles as success → "resolved".Rejected? No — state is locked to resolved.Compare still yields false.Frequently Asked Questions What did deferred.isRejected() do? isRejected() returned true when the Deferred had been rejected (fail path), and false while pending or after a successful resolve. It took no arguments.
Does isRejected() still work in modern jQuery? No. It was deprecated in jQuery 1.7 and removed in 1.8. In current jQuery, use dfd.state() === "rejected" instead.
How do I check for rejection today? Call deferred.state(). It returns "pending", "resolved", or "rejected". Compare with === "rejected" for the old isRejected() meaning.
Is isRejected() the same as fail()? No. fail() registers a callback for when rejection happens. isRejected() (and state()) are synchronous status checks — they do not listen for future rejects.
When should I check state()? At known checkpoints — after reject(), inside fail(), or for debugging. Prefer fail()/catch() for reacting to errors instead of polling.
Can a Deferred be rejected and resolved? No. Once settled, the state is locked. state() is "rejected" only after reject()/rejectWith(), never after resolve().
CODETOFUN NEWS
Stay Ahead in Tech Get the latest IT news, programming updates, and technology trends directly on your phone.
About the author Developer, cloud engineer, and technical writer
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
Helpful Share Copy link Suggestion