小编v g*_*eat的帖子

为什么输出结果不同?

async function fn1() {
  return 1
}
async function fn2() {
  return Promise.resolve(1)
}

function fn3() {
  return Promise.resolve(1)
}

function fn4() {
  return Promise.resolve(Promise.resolve(1))
}
console.log(fn1()); //Promise {<fulfilled>: 1}
console.log(fn2()); // Promise {<pending>}
console.log(fn3()); // Promise {<fulfilled>: 1}
console.log(fn4()); // Promise {<fulfilled>: 1}
Run Code Online (Sandbox Code Playgroud)

当我运行 fn2() 时,它输出Promise { pending }.

为什么是 fn2()Promise { pending }而不是Promise {fulfilled: 1}

javascript

7
推荐指数
1
解决办法
148
查看次数

标签 统计

javascript ×1