1-1 promise和定时器
<!--
知识点:异步
面试题: promise和定时器执行顺序的问题:
promise会优先于定时器去执行
-->
<script>
console.log("3");
setTimeout(() => {
console.log(2)
});
Promise.resolve().then(()=>{
console.log(1)
})
</script>
1-2 await
/* await 阻塞线程 会从异步函数中跳出来,优先执行同步代码 */
async function show(){
console.log(1);
var res = await 100;
console.log(res);
}
show();
console.log(2);
setTimeout(() => {
console.log(3)
}, 1000);
/*
1
2
100
3
*/