JS的执行顺序 setTimeout与Promise async/await
今天碰到一个很经典js执行顺序的题 代码不是很长
问的是console.log的输出顺序
这道题涉及到的知识点还挺多的
async function async1() {
console.log("async1start");
await async2();
console.log("async1end");
}
//函数2
async function async2() {
console.log('async2')
}
console.log("scriptstart");
setTimeout(function () {
console.log("settimeout");
}, 0)
async1()
new Promise(function (resolve) {
console.log("promise1");
resolve();
}).then(function () {
console.log("promise2");
});
console.log('script end');
//执行结果
scriptstart
async1start
async2
promise1
script end
async1end
promise2
settimeout

浙公网安备 33010602011771号