美文网首页
事件循环面试题目

事件循环面试题目

作者: ?尛孞 | 来源:发表于2019-03-29 11:41 被阅读0次

来看两道题目

题目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

相关文章

网友评论

      本文标题:事件循环面试题目

      本文链接:https://www.haomeiwen.com/subject/qoflbqtx.html