There are two cases, both return Promise and are chained with the following then methods. But the result sequence is different. Some notes: Promise.resolve(value) -> returns immediately fulfilled Promise with the value. And in the then method when we return value again it returns fulfilled Promise with the value. Logically there shouldn't be any difference. Both are immediate... Thanks in advance...
Promise.resolve(1)
.then((v) => {
console.log(v);
return Promise.resolve(v + 1);
})
.then((v) => {
console.log(v);
return Promise.resolve(v + 1);
})
.then((v) => {
console.log(v);
return v + 1;
})
.then((v) => {
console.log(v);
return v + 1;
});
Promise.resolve(10)
.then((v) => {
console.log(v);
return v + 1;
})
.then((v) => {
console.log(v);
return v + 1;
})
.then((v) => {
console.log(v);
return v + 1;
})
.then((v) => {
console.log(v);
return v + 1;
});
//Result on the console:
//1
//10
//11
//12
//2
//13
//3
//4
//
Promise.resolve(1)
.then((v) => {
console.log(v);
return v + 1;
})
.then((v) => {
console.log(v);
return v + 1;
})
.then((v) => {
console.log(v);
return v + 1;
})
.then((v) => {
console.log(v);
return v + 1;
});
Promise.resolve(10)
.then((v) => {
console.log(v);
return v + 1;
})
.then((v) => {
console.log(v);
return v + 1;
})
.then((v) => {
console.log(v);
return v + 1;
})
.then((v) => {
console.log(v);
return v + 1;
});
//Result on the console:
//1
//10
//2
//11
//3
//12
//4
//13