个人理解,方便记忆
js单线程,自上而下执行
先走一遍主代码块,遇到谁调用先执行谁,特殊(遇到setInterval,setTimeout直接放最后执行),(遇到promise,async和await内部内容直接执行,但promise的then和catch以及async的await后的内容第二波一波带走,谁的主任务在前,谁优先执行)
举个例子:
setInterval(()=>{ 001 console.log('001') 1 }) 2 setTimeout(()=>{ 3 4(resolve)/5(reject) 002 console.log(002) 6 }) 7 8 new Promise((resolve,reject)=>{ 1 console.log('1') resolve() 顺序:左边 1,2,3,6,7,10,4,8,001,002,001... console.log('2') reject() console.log('3') }).then(()=>{ console.log('4') }).catch(()=>{ console.log('5') }) aa() async funtion aa(){ console.log('6') await console.log('7') console.log('8') } function bb(){ console.log('10') }
bb()
标签:resolve,console,log,前端,await,js,001,代码执行,reject From: https://www.cnblogs.com/wdxue/p/16850587.html