When working with promises in JavaScript, we have a possibility to use .then
, .catch
and .finally
. Each of these methods returns a new Promise
object.
Using .then
is pretty straightforward - we chain them. The use case for finally - is to put it at the end of the chain of .then
and .catch
. But
In the code below, as I understand, we initialize promise p
which can resolve or reject. I could use .then(resolutionHandler, rejectionHandler)
, which would be self-explanatory as it's only 1 .then
"handler" with both handlers, but in case of sequencing .then
and .catch
instead of the latter approach-
**Are .then
and .catch
handlers somehow paired and treated like .then(resolutionHandler, rejectionHandler)
? or something else is happening? **
const p = new Promise((resolve, reject) => {
reject("ups...");
});
p
.then(data => {
// this is success handler for Promise "p"
})
.catch(err => {
// Is this failure handler for Promise "p"?
})