jQuery Deferred state() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Deferred

Definition

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()
CallWhat it does
ArgumentsMethod takes no parameters
Return"pending" | "resolved" | "rejected"
SincejQuery 1.7

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Hold a Deferred or its promise().
Step 2Call state() at a checkpoint (after a settle, in a test, while debugging).
Step 3Compare to "pending", "resolved", or "rejected".

Return Value

Return ValueDescription
BooleanOften true or false depending on the match or state.
Value / undefinedGetters 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
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).

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".

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.

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.promise() Method

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

deferred.promise() Method tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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