JS事件循环机制练习题
题目一:
================================================================================
=========答案分割线==============================================================
=================================================================================
================================================================================
=================================================================================
输出顺序:2 4 5 7 9 3 1 6 8
题目二:
async function async1() { console.log("async1 start") await async2() console.log("asyncl end") } async function async2() { console.log("async2") } console.log("script start") setTimeout(function () { console.log("setTimeout") }, 0) async1() new Promise(function (resolve) { console.log("promisel") resolve() }).then(function () { console.log("promise2") }) console.log("script end")
================================================================================
=========答案分割线==============================================================
=================================================================================
================================================================================
=================================================================================
输出:scirpt start
async1 start
async2
promise1
script end
async1 end
promise2
setTimeout
题目三:
let body =document.body; body.addEventListener('click', function (){ Promise.resolve().then(()=>{ console.log(1); }); console.log(2); }); body.addEventListener('click',function (){ Promise.resolve().then(()=>{ console.log(3); }); console. log(4); });
================================================================================
=========答案分割线==============================================================
=================================================================================
================================================================================
=================================================================================
输出:2 1 4 3

浙公网安备 33010602011771号