闲着的前端牛牛们,来做一道异步输出题
async function async1() {
console.log('async1 start');
await async2();
console.log('async1 end');
}
async function async2() {
console.log('async2 start');
return new Promise((resolve,reject)=>{
resolve();
console.log("async2 promise")
})
}
console.log('script start');
setTimeout(function () {
console.log('setTimeout');
}, 0)
async1();
new Promise(function (resolve) {
console.log('promise1');
resolve();
}).then(function () {
console.log('promise2');
}).then(function () {
console.log('promise3');
});
console.log('script end');
console.log('async1 start');
await async2();
console.log('async1 end');
}
async function async2() {
console.log('async2 start');
return new Promise((resolve,reject)=>{
resolve();
console.log("async2 promise")
})
}
console.log('script start');
setTimeout(function () {
console.log('setTimeout');
}, 0)
async1();
new Promise(function (resolve) {
console.log('promise1');
resolve();
}).then(function () {
console.log('promise2');
}).then(function () {
console.log('promise3');
});
console.log('script end');
全部评论
我选择编译器跑一下
1.script start
2.async1 start
3.async2 start
4.async2 promise
5.promise1
6.script end
7.aysnc1 end
8.promise2
9.promise3
10.setimeout
里面可能第二个async2 promise顺序可能不对
我咋感觉和同程旅行的一个面试题很像
大晚上看得眼睛花,老哥早点休息吧
相关推荐