<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width, initial-scale=1.0"><title>await/async案例笔记</title></head><body><scripttype="text/javascript">functiondelayGetTime(){returnnewPromise((resolve, reject)=>{setTimeout(()=>{resolve(Date.now())},2000)})}asyncfunctionsyncTest(){let result =[];result.push(awaitdelayGetTime())result.push(awaitdelayGetTime())return result
}(async()=>{console.log(1)console.log(awaitsyncTest());console.log(2)// 没有await堵塞又按主线程控制先同步后异步,先宏任务后微任务delayGetTime().then(t=> console.log(t));console.log(3)})();</script></body></html>