异步面试题

242 阅读1分钟

每日一练

题目
 console.log("script start");

    async function async1(){
      await async2();
      console.log('async1 end');
    }

    async function async2(){
      console.log('async2 end')
    }

    async1();

    setTimeout(function(){
      console.log('setTimeout')
    }, 0);
    
    new Promise(resolve =>{
      console.log('promise');
    }).then(function(){
      console.log('promise1');
    }).then(function(){
        console.log('promise2');
    });
    console.log('script end');

答案
 script start
 async2 end
 promise
 script end
 async1 end
 Live reload enabled.
 setTimeout