笔试的一道题目,求解答

console.log(0); Promise.resolve() .then(()=>{ setTimeout(()=>{ console.log(1); },0); }) .then(()=>{ console.log(2); }); console.log(4); 输出结果为: 0 4 2 1 请问为什么?#笔试题目#
全部评论
Settimeout为宏任务,then为微任务。console为同步任务。考察js的运行机制,去百度找找解析吧,promise是立即执行。
点赞 回复 分享
发布于 2018-05-08 15:23

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务