jskatas.org Continuously Learn JavaScript. Your Way.

Promise: chaining then()

Chaining promises can enhance readability of asynchronous code.

Donate to NGO Julenka. Support Ukranians in need. Julenka is an NGO which my brother founded in 2011 to support Ukranian families and kids in need.

chaining multiple promises can enhance readability

prerequisites for understanding

  • reminder: the test passes when a fulfilled promise is returned
  • a function given to then() fulfills (if it doesnt throw)

chain promises

  • then() receives the result of the promise it was called on
  • multiple then()s can be chained
  • order of the then()s matters
  • any of the things given to then() can resolve asynchronously (the real power of Promises)
  • also asynchronously, the order still matters, promises wait, but don`t block

Links

The description of how a value given to `then()` becomes a resolved promise.
Looks like the description in the spec of what `then()` accepts and does with the given value.
A long article introducing promises.