Predict Promise.然后链
预测输出 中等
题目
什么做 这个 code print?
代码
Promise.resolve(5)
.then(x => x + 3)
.then(x => x * 2)
.then(x => console.log(x));
提示
每个然后接收 result 的上一个 one.
解释
链开始使用 Promise.resolve(5). 首先 .然后: 5 + 3 = 8. 其次 .然后: 8 * 2 = 16. 第三 .然后: console.log(16) prints 16. 每个 .然后 接收 resolved 值从 上一个步骤 and 通过它的返回值 到下一个.
相关资源
相关课程
- 异步 JavaScript
学习关于 Promise 链.
查阅不认识的术语
新手友好的术语表用大白话解释编程术语——变量、函数、DOM、Promise 等等。
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。
动手做项目
通过引导式项目应用所学,含起始代码与解决方案。