Skip to content

下面代码的输出是什么?

javascript
fetch('https://www.website.com/api/user/1')
  .then(res => res.json())
  .then(res => console.log(res))

A. fetch方法的结果 B. 第二次调用fetch方法的结果 C. 前一个.then()中回调方法返回的结果 D. 总是undefined

答案: C

解析:

第二个.thenres的值等于前一个.then中的回调函数返回的值。 你可以像这样继续链接.then,将值传递给下一个处理程序。