事件循环面试题目

来看两道题目

题目1:

async function async1() {
    console.log('async1 start');
    await async2();
    console.log('async1 end');
}
async function async2() {
    console.log('async2');
}
console.log('script start');
setTimeout(function() {
    console.log('setTimeout');
}, 0) 
async1();
new Promise(function(resolve) {
    console.log('promise1');
    resolve();
}).then(function() {
    console.log('promise2');
})
console.log('script end');

题目详解参见
https://www.qdfuns.com/article/18271/88153fb28368c185faf062b88ed62e5a.html?tdsourcetag=s_pcqq_aiomsg

题目二:

console.log('1');
setTimeout(function() {
    console.log('2');
    new Promise(function(resolve) {
        console.log('3');
        resolve();
    }).then(function() {
        console.log('4');
    })
})
new Promise(function(resolve) {
    console.log('5');
    resolve();
}).then(function() {
    console.log('6');
})
setTimeout(function() {
    console.log('7');
})
setTimeout(function() {
    console.log('8');
    new Promise(function(resolve) {
        console.log('9');
        resolve();
    }).then(function() {
        console.log('10');
    })
})
new Promise(function(resolve) {
    console.log('11');
    resolve();
}).then(function() {
    console.log('12');
})
console.log('13');

题目Event Loop原理详解
https://www.cnblogs.com/hity-tt/p/6733062.html

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容