liveBook · Manning

Fulfilled state

As explained in Secrets of the JavaScript Ninja, Second Edition

The promise state indicating successful completion with a value.

A fulfilled promise has successfully obtained its promised value. It enters this state when its resolve function is called, and cannot later switch to rejected or another state. section 6.3.2

A value arrives

A promise resolved immediately with "Hattori" fulfills; its then success callback receives that value. A timeout can also resolve a promise later with "Hattori". section 6.3 section 6.3.2

Listing 6.10. Creating a simple promise
const ninjaPromise = new Promise((resolve, reject) => {      #A
  resolve("Hattori");                                        #B
  //reject("An error resolving a promise!");                 #B
});

ninjaPromise.then(ninja => {                                 #C
  assert(ninja === "Hattori", "We were promised Hattori!");  #C
}, err => {                                                  #D
  fail("There shouldn't be an error")                        #D
});                                                          #D

See a promise resolve with a value and pass it to the success callback. section 6.3

How Secrets of the JavaScript Ninja, Second Edition covers it

How deep it goes
Explains entry through resolve and permanence after fulfillment, alongside pending and rejected states.
Examples
Uses immediate and timeout-delayed promises that resolve with "Hattori".
What you can do after
Understand that a fulfilled promise has a value and cannot later change state.
How it connects
Connects promise fulfillment to resolve, then callbacks, and the pending and rejected states.

Also explained in

Compare how 2 books explain fulfilled state →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Secrets of the JavaScript Ninja, Second Edition. The section links point to the parts of the book it draws on.