async 异步
await 等待
两者通常为成对出现
通常为等待一个异步方法执行
// 定义一个异步方法
async function getAge(){
return "20";
}
console.log(getAge());
async function setAge(){
//等待异步方法执行
const data=await getAge();
console.log(data);
}
setAge();
输出
20
async 异步
await 等待
两者通常为成对出现
通常为等待一个异步方法执行
// 定义一个异步方法
async function getAge(){
return "20";
}
console.log(getAge());
async function setAge(){
//等待异步方法执行
const data=await getAge();
console.log(data);
}
setAge();
输出
20