jQuery Deferred state() Method

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Read Deferred status

What You’ll Learn

The state() method returns whether a jQuery Deferred is "pending", "resolved", or "rejected". This tutorial covers syntax, five examples, comparisons with isResolved() and isRejected(), and when to inspect state vs use callbacks.

01

Syntax

dfd.state()

02

pending

Not settled

03

resolved

Success

04

rejected

Failure

05

Read-only

No side effects

06

Since 1.7

Preferred in 3+

Introduction

Every jQuery Deferred has a lifecycle: it starts pending, then settles exactly once as resolved (success) or rejected (failure). The state() method lets you read that status synchronously — like glancing at a traffic light without changing it.

In jQuery 3.0+, state() is the recommended way to inspect status. It replaces the older boolean helpers isResolved() and isRejected() with one clear string return value.

Understanding the state() Method

state() takes no arguments and returns a string. It does not register callbacks and does not change the Deferred — it only reports the current status at the moment you call it.

A Deferred can never be both resolved and rejected. After settlement, state() always returns the same value for that object.

💡
Beginner Tip

Calling state() immediately after starting async work often returns "pending" — that is expected. Check again inside done(), fail(), or always(), or after you know resolve() / reject() has run.

📝 Syntax

General form of deferred.state:

jQuery
deferred.state()

Parameters

  • None — state() is a read-only inspector.

Return value

  • "pending" — the Deferred has not been resolved or rejected yet.
  • "resolved" — settlement succeeded via resolve() or resolveWith().
  • "rejected" — settlement failed via reject() or rejectWith().

Minimal example

jQuery
const dfd = $.Deferred();

console.log(dfd.state());  // "pending"

dfd.resolve("OK");
console.log(dfd.state());  // "resolved"

⚡ Quick Reference

GoalCode
Read current statusdfd.state()
Check if still waitingdfd.state() === "pending"
Check if succeededdfd.state() === "resolved"
Check if faileddfd.state() === "rejected"
React to outcome (preferred)dfd.done(fn) / dfd.fail(fn)

📋 state() vs isResolved() vs isRejected()

One string vs two booleans — modern jQuery favors state().

state()
"pending" | …

Three-way status

isResolved()
true / false

Success only

isRejected()
true / false

Failure only

jQuery 3+
prefer state

Booleans deprecated

Examples Gallery

Each example shows state() at different points in a Deferred’s lifecycle. Use the Try-it links to run them interactively.

📚 Getting Started

Watch state() move from pending to resolved after resolve().

Example 1 — From Pending to Resolved

Log state() before and after settlement.

jQuery
const dfd = $.Deferred();

console.log("before resolve:", dfd.state());  // "pending"

dfd.resolve("Data loaded");

console.log("after resolve:", dfd.state());   // "resolved"
Try It Yourself

How It Works

Every new Deferred starts as "pending". Calling resolve() locks the state to "resolved" permanently.

Example 2 — Rejected State

After reject(), state() returns "rejected" — not pending, not resolved.

jQuery
const dfd = $.Deferred();

dfd.reject("Network error");

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

How It Works

Success and failure are mutually exclusive. A rejected Deferred never reports "resolved".

📈 Practical Patterns

Compare legacy booleans, check at the right time, and branch on status strings.

Example 3 — state() vs Legacy Boolean Methods

One resolved and one rejected Deferred — see how all three APIs relate.

jQuery
function logStatus(label, dfd) {
  console.log(label);
  console.log("  state():", dfd.state());
  console.log("  isResolved():", dfd.isResolved());
  console.log("  isRejected():", dfd.isRejected());
}

logStatus("resolved dfd", $.Deferred().resolve("ok"));
logStatus("rejected dfd", $.Deferred().reject("err"));
Try It Yourself

How It Works

state() tells you pending vs resolved vs rejected in one call. The boolean helpers only answer their specific question.

Example 4 — Async Work — Check Inside Callbacks

Simulated async load: state() is pending until the timer resolves — inspect inside always().

jQuery
const dfd = $.Deferred();

console.log("start:", dfd.state());  // "pending"

setTimeout(function () {
  dfd.resolve("Loaded");
}, 600);

dfd.always(function () {
  console.log("in always():", dfd.state());  // "resolved"
});
Try It Yourself

How It Works

This replaces the old reference pattern that polled state() on a fake AJAX URL. Use callbacks — not busy loops — to react when settlement happens.

Example 5 — Branch with switch on state()

A small helper picks UI messages based on the current status string.

jQuery
function statusMessage(dfd) {
  switch (dfd.state()) {
    case "pending":
      return "Loading…";
    case "resolved":
      return "Success!";
    case "rejected":
      return "Something went wrong.";
    default:
      return "Unknown";
  }
}

const loading = $.Deferred();
console.log(statusMessage(loading));  // Loading…

loading.resolve();
console.log(statusMessage(loading));  // Success!
Try It Yourself

How It Works

switch (dfd.state()) is readable for UI labels, tests, and debug panels — especially when you need to handle all three outcomes explicitly.

🚀 Use Cases

  • Debug logging — print Deferred status during development to trace async flows.
  • Unit tests — assert dfd.state() === "resolved" after exercising an API.
  • UI status labels — show Loading / Done / Error based on the current string.
  • Guard clauses — skip follow-up logic when a Deferred is still "pending".
  • Batch inspection — after $.when(), check individual Deferreds in a collection.

🧠 The Three state() Values

1

pending

Default at creation — async work may still complete or fail.

Wait
2

resolved

resolve() or resolveWith() ran — success path taken.

OK
3

rejected

reject() or rejectWith() ran — failure path taken.

Fail
=

One final state

After resolved or rejected, state() never changes again for that Deferred.

📝 Notes

  • state() is read-only — it never resolves or rejects the Deferred.
  • In jQuery 3.0+, prefer state() over deprecated isResolved() / isRejected().
  • "pending" does not mean failure — it means not settled yet.
  • For user-facing success/error UI, use done() and fail() rather than polling state().
  • jqXHR objects from $.ajax() follow the same pending → resolved/rejected lifecycle.

Browser Support

deferred.state() has been available since jQuery 1.7. It is the recommended status API in jQuery 3.0+.

jQuery 1.7+

jQuery Deferred.state()

Supported in jQuery 1.7+, 2.x, and 3.x wherever jQuery Deferred runs. Replaces isResolved/isRejected for new code in jQuery 3+.

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

Bottom line: Use state() for readable three-way status checks. Pair with done/fail callbacks for production async handling.

🎉 Conclusion

The deferred.state() method gives you a clear snapshot of where a Deferred stands: "pending", "resolved", or "rejected". Use it for debugging, tests, and conditional checks — and use done() / fail() to react when work completes.

Next, explore then() to chain success and failure handlers, or review resolve() and reject() for how states get set in the first place.

💡 Best Practices

✅ Do

  • Use state() in jQuery 3+ instead of boolean helpers
  • Check inside done(), fail(), or always()
  • Handle all three strings when branching explicitly
  • Use for tests and debug output
  • Combine with callbacks for production user flows

❌ Don’t

  • Poll state() in a tight loop
  • Assume "pending" means failure
  • Rely on state alone for critical success UI
  • Expect state to change after settlement
  • Ignore deprecation — migrate from isResolved/isRejected

Key Takeaways

Knowledge Unlocked

Five things to remember about state()

How to read Deferred status in one call.

5
Core concepts
02

pending

Not settled

Wait
03

resolved

Success

OK
04

rejected

Failure

Err
3+ 05

Modern

vs booleans

Prefer

❓ Frequently Asked Questions

state() returns a string: "pending" while the Deferred has not settled, "resolved" after resolve() or resolveWith(), or "rejected" after reject() or rejectWith(). Once settled, the value never changes.
state() returns one of three strings in a single call. isResolved() and isRejected() each return true/false booleans. In jQuery 3.0+, state() is preferred — the boolean methods are deprecated but still work.
Yes. jQuery promises expose state() too. Consumers can inspect status read-only without being able to resolve or reject.
Use state() for synchronous inspection at a known checkpoint — debugging, tests, or branching when you already know settlement may have happened. For reacting to outcomes, prefer done(), fail(), then(), or always() callbacks.
Yes. A Deferred remains pending until the owner calls resolve(), reject(), or the matching With methods. Unsettled Deferreds never become resolved or rejected on their own.
Usually no. Polling wastes CPU. Register done(), fail(), or always() handlers, or check state() once at logical points — for example inside a callback after you expect settlement.
Did you know?

Native JavaScript Promises use promise.then() for reactions but expose no public state() method — you cannot synchronously read pending vs fulfilled vs rejected on a standard Promise. jQuery’s Deferred adds state() as a practical inspection hook, which is one reason jQuery’s promise-like objects feel different from native Promises.

Continue to then()

Learn how to chain success and failure callbacks on a Deferred.

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.

6 people found this page helpful