async function helloAsync() {
return "Hello Async"
}
console.log('返回非promise自动转换', helloAsync())
helloAsync().then(res => {
console.log("res", res)
})
async function helloAsync2() {
return new Promise((resolve, reject) => {
})
}
console.log('返回pending状态的Promise', helloAsync2())
helloAsync2().then(res => {
console.log("res2", res)
})
async function helloAsync3() {
return new Promise((resolve, reject) => {
resolve("Hello Async 3")
}
)
}
console.log('返回resolved状态的Promise', helloAsync3())
helloAsync3().then(res => {
console.log("res3", res)
})
async function helloAsync4() {
try {
const res1 = await fetch('https://www.baidu.com')
const res2 = await fetch('https://www.google.com')
return res1.text() + res2.text()
} catch (error) {
console.log('error', error)
}
}
helloAsync4().then(res => {
console.log("res4", res)
})
