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.
Syntax
Start with these common calls. Keep them short and readable.
jQuery
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()
Call
What it does
Arguments
Method takes no parameters
Return
"pending" | "resolved" | "rejected"
Since
jQuery 1.7
Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.
Parameters
Parameter
Description
Step 1
Hold a Deferred or its promise().
Step 2
Call state() at a checkpoint (after a settle, in a test, while debugging).
Step 3
Compare to "pending", "resolved", or "rejected".
Return Value
Return Value
Description
Boolean
Often true or false depending on the match or state.
Value / undefined
Getters usually return a value from the first matched element, or undefined when nothing applies.
jQuery Examples
Example 1 — Fresh Deferred Is Pending
Before any settle call, state() is "pending".
jQuery
var dfd = $.Deferred();
console.log(dfd.state()); // pending
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.