전단 면접문제 정리-이벤트 루프에 관한(1)

1605 단어
다음 코드는 인쇄 값 순서를 출력합니다.
    async function async1(){
        console.log('async1 start');
        await async2();
        console.log('async1 end');
    }
    async function async2(){
        console.log('async2');
    }
    console.log('script start');
    setTimeout(function(){
        console.log('setTimeout')
    },0)
    async1();
    new Promise(function(resolve){
        console.log('promise1');
        resolve();
    }).then(function(){
        console.log('promise2');
    })
    console.log('script end')

시험 장소:
JS에서 EventLoop을 실행하는 메커니즘
매크로 작업과 마이크로 작업의 실행 순서입니다.(마이크로 퀘스트 먼저 실행, 매크로 퀘스트 후 실행)
매크로 작업에 속하는 작업과 마이크로 작업에 속하는 작업:
매크로 작업:
I/O、setTimeout、setInterval、setImmediate、requestAnimationFrame
마이크로 작업:
process.nextTick、MutationObserver、Promise.then catch finally

좋은 웹페이지 즐겨찾기