微任务
Promise , async , await
宏任务
setTimeout ,setInterval , DOM事件 ,AJAX请求
- JS是单线程执行
- 顺序 : 同步代码 ----> 微任务 ----> DOM渲染 ----> 宏任务
- 是一个存储函数调用的栈结构,遵循先进后出的原则
- Event Loop 循环机制
console.log(1);
setTimeout(() => {
console.log(2)
}, 0);
Promise.resolve().then(() => {
console.log(3)
})
console.log(4);
//Dom
const $content = $('<p>内容</p>');
$('#box').append($content);
console.log(1);
setTimeout(()=>{
console.log(2);
},0);
Promise.resolve().then(()=>{
console.log(3);
alert('promise then ');
});
console.log(4);