每日一测(二)

Promise

1
2
3
4
5
6
7
8
9
Promise.resolve(1)
.then((res) => {
console.log(res);
return 2;
}).catch((err) => {
return 3;
}).then((res) => {
console.log(res);
});

答案:1 2

  1. 如果调用resolve函数和reject函数时带有参数,那么这些参数会被传递给回调函数,因此首先打印1
  2. 如果then方法有两个回调函数,那么第一个回调完成后,返回的结果会作为参数传入第二个回调函数,因此打印2