What will be the order of the following code:
Promise.resolve(1)
.then(() => 2)
.then(3)
.then((value) => value * 3)
.then(Promise.resolve(4))
.then(console.log);
The output will be: 6
Promise.resolve(1)
β Initial value is 1
.then(() => 2)
β Returns 2
.then(3)
β Ignored because 3
is not a function, passes previous value 2
.then((value) => value * 3)
β 2 * 3 = 6
.then(Promise.resolve(4))
β Ignored because it's not a function, passes previous value 6
.then(console.log)
β Prints 6
Key points:
.then()
receives a non-function (like 3
or Promise.resolve(4)
), it ignores that handler and passes the previous value through