jQuery Deferred state() Method

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

What Is state()?

deferred.state() returns a string for the current Deferred status (since jQuery 1.7). It takes no arguments. Official docs note it is mainly useful for debugging — for example, checking whether something already resolved when you expected a reject.

Remember
deferred.state()  → String

"pending"   → not settled yet
"resolved"  → resolve() / resolveWith() ran
"rejected"  → reject() / rejectWith() ran

once settled → state never changes
prefer callbacks over polling state()
NeedUse
Read status nowdfd.state()
React when finisheddone() / fail() / then()
Boolean helpers (older)isResolved() / isRejected()

How to Use state()

Call it with no arguments; compare the returned string.

  1. Hold a Deferred or its promise().
  2. Call state() at a checkpoint (after a settle, in a test, while debugging).
  3. Compare to "pending", "resolved", or "rejected".
  4. For normal async flow, attach done/fail/then instead of looping on state().
PieceRequired?Role
ArgumentsNoneMethod takes no parameters
Return—"pending" | "resolved" | "rejected"
Since—jQuery 1.7

Pseudocode

Pseudocode
state():
    if not settled yet: return "pending"
    if resolve / resolveWith was called: return "resolved"
    if reject / rejectWith was called: return "rejected"

// after either settle:
//   state() always returns the same string

Cheat Sheet

Keep these facts handy when inspecting Deferred status.

TopicDetail
Syntaxdeferred.state()
Valuespending · resolved · rejected
On PromiseYes — read-only via promise()
Settled?state() !== "pending"
vs callbacksInspect now vs react later
Best useDebug / tests / one-shot checks
SincejQuery 1.7

Live Preview

Settle a Deferred different ways and watch state() change.

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

Result
state() → "pending"

/* neither resolve nor reject yet */

jQuery Examples

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

Example 1 — Fresh Deferred Is Pending

Before any settle call, state() is "pending".

jQuery
var dfd = $.Deferred();
console.log(dfd.state());  // pending
Try It Yourself

How It Works

  1. Create a Deferred. No resolve or reject yet.
  2. Call state(). Returns the string "pending".
  3. Meaning. Work has not finished (success or failure).
  4. Next step. Owner will settle later with resolve or reject.

Example 2 — After resolve()

Successful settle flips state to "resolved".

jQuery
var dfd = $.Deferred();
console.log(dfd.state());  // pending

dfd.resolve("ok");
console.log(dfd.state());  // resolved
Try It Yourself

How It Works

  1. Start pending. Log before settle.
  2. Call resolve. Success path runs (done handlers).
  3. State updates. Now "resolved".
  4. Locked. Further reject/resolve calls do not change it.

Example 3 — After reject()

Failure settle flips state to "rejected".

jQuery
var dfd = $.Deferred();
dfd.reject("error");
console.log(dfd.state());  // rejected
Try It Yourself

How It Works

  1. Reject the Deferred. Fail handlers run.
  2. Read state. Returns "rejected".
  3. Same idea as resolved. Settlement is permanent.
  4. Debug tip. Useful when you expected success but got failure.

Example 4 — state() on a Promise

Callers can inspect status without gaining settle methods.

jQuery
var dfd = $.Deferred();
var p = dfd.promise();

console.log(p.state());       // pending
console.log(typeof p.resolve); // undefined

dfd.resolve("ok");
console.log(p.state());       // resolved
Try It Yourself

How It Works

  1. Create a Promise view. promise() shares the same status.
  2. Inspect safely. p.state() works; p.resolve does not exist.
  3. Owner settles. Only dfd can resolve.
  4. Promise updates. p.state() becomes "resolved".

Example 5 — Branch on Current State

Use a one-shot check when you may already be settled (not a polling loop).

jQuery
function label(dfd) {
  var s = dfd.state();
  if (s === "pending") return "still working";
  if (s === "resolved") return "success";
  return "failed";
}

var dfd = $.Deferred();
console.log(label(dfd));  // still working
dfd.resolve();
console.log(label(dfd));  // success
Try It Yourself

How It Works

  1. Read once. label calls state() at the moment you ask.
  2. Map to words. Three strings → three friendly labels.
  3. Before settle. Shows still working.
  4. After resolve. Shows success — a checkpoint check, not a busy loop.

Edge Cases & Pitfalls

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

poll

Do not poll in a tight loop

Busy-waiting on state() burns CPU. Prefer done/fail/always for completion.

locked

State never flips back

After resolve or reject, state() stays that value forever for that Deferred.

debug

Official primary use is debugging

Docs highlight checking whether a Deferred already resolved when you meant to reject — great for tests and logs.

legacy

Prefer state() over boolean helpers

isResolved() / isRejected() only cover two cases; state() covers all three in one call.

Browser Support

deferred.state() needs jQuery 1.7+ loaded. It works across jQuery 1.7–3.x on both Deferreds and Promises from promise().

✓ jQuery 1.7+

deferred.state()

Works in Chrome, Firefox, Safari, and Edge when jQuery 1.7+ is loaded. Returns pending, resolved, or rejected.

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

Bottom line: Safe wherever modern jQuery Deferreds exist. Use callbacks for flow control; use state() for inspection.

Performance Notes

ApproachCostBest for
state() onceO(1)Debug / checkpoint
done / failEvent-drivenNormal completion handling
Polling state()Wastes CPUAvoid

A single state() read is cheap. The anti-pattern is spinning until it changes — register handlers instead.

Key Takeaways

  • Role: return pending, resolved, or rejected.
  • Locked: after settle, the string never changes.
  • Promise OK: inspect status without settle methods.
  • Prefer callbacks for flow; use state() for inspection.

One line: state() tells you where a Deferred is now — pending, resolved, or rejected.

Frequently Asked Questions

A string: "pending" before settlement, "resolved" after resolve()/resolveWith(), or "rejected" after reject()/rejectWith(). Once settled, the value never changes.
state() returns one of three strings in a single call. isResolved() and isRejected() return booleans. Prefer state() — the boolean helpers are older and less convenient.
Yes. Promises expose state() for read-only inspection without allowing resolve or reject.
Use state() for a synchronous check at a known point (debug, tests, branching after possible settlement). To react when work finishes, prefer done(), fail(), then(), or always().
Yes. A Deferred stays pending until the owner calls resolve, reject, or a *With variant.
Usually no. Polling wastes CPU. Register callbacks, or check state() once at logical checkpoints.

Next: deferred.then()

Learn how to chain success and failure handlers on a Promise.

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