在学会异步代码如何同步执行之前,需要先了解两个知识
async function fn() {
let a = await 1;
let b = await new Promise(function (res,rej){
setTimeout(function (){
res(2);
})
});
let c = 3;
console.log(a,b,c); //打印结果为:1,2,3
return 'hello world';
}
fn().then(function (val){
console.log(val); // 打印结果为:'hello world'
})