This is my code, I don't know what happened when I using the async keyword, if remove the async keyword, the result of print is different
async function async2() {
return new Promise((resolve) => resolve('hello'))
}
async2().then((res) => {
console.log(res)
console.log('async1')
})
Promise.resolve()
.then(() => {
console.log(1)
})
.then(() => {
console.log(2)
})
.then(() => {
console.log(3)
})
it will print
1
2
hello
async1
3
If remove the async keyword of async2 function, it will print
hello
async1
1
2
3
function async2() {
return new Promise((resolve) => resolve('hello'))
}
async2().then((res) => {
console.log(res)
console.log('async1')
})
Promise.resolve()
.then(() => {
console.log(1)
})
.then(() => {
console.log(2)
})
.then(() => {
console.log(3)
})
What will happen if an async function intentionally returns a promise?
I want to know what happened when I add the async keyword.