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+
Fundamentals
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.
Concept
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.
Foundation
📝 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().
switch (dfd.state()) is readable for UI labels, tests, and debug panels — especially when you need to handle all three outcomes explicitly.
Applications
🚀 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.
Important
📝 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.
Compatibility
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 ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll 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.
Wrap Up
🎉 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.
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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about state()
How to read Deferred status in one call.
5
Core concepts
📝01
Returns
String status
API
⏳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.