js学习笔记 -- await/ async
- await 暂停async function函数,等待Promise处理完成,若Promise 状态为fulfilled,其回调resolve的参数作为await的值,Promise 状态为rejected, await 将其回调rejected参数抛出。
- await 关键字仅仅在 async function中有效。
(async function () { let a = await Promise.resolve('xxx') console.log(a)//xxx })(); (async function () { try { let a = await Promise.reject('yyy') console.log('over')//不执行 }catch (e){ console.log(e)//yyy } })();