1. async function test1() {
    2. console.log('test1 begin');
    3. const result = await test2();
    4. console.log('result', result);
    5. console.log('test1 end');
    6. }
    7. async function test2(){ // 异步函数默认返回一个 Promise
    8. console.log('test2');
    9. return Promise.reslove('haha')
    10. }
    11. console.log('script begin');
    12. test1();
    13. console.log('script end');

    输出

    1. script begin
    2. test1 begin
    3. test2
    4. script end
    5. result haha
    6. test1 end

    可以把 await后面的代码当成一个 setTimeout(()=>{}) 包裹住(是异步), 以便理解