async function a1() {
console.log(1);
const data = await a2();
// const data = await new Promise(res=> res()).then(()=>{console.log(2)});
console.log(5);
}
async function a2() {
return new Promise(res=> res()).then(()=>{console.log(2)})
}
a1();
new Promise(function(res) {
res()
}).then(() => { console.log(3) })
.then(() => { console.log(4) })
.then(() => { console.log(6) })
async function a1() {
console.log(1);
const data = await new Promise(res=> res()).then(()=>{console.log(2)});
console.log(5);
}
a1();
new Promise(function(res) {
res()
}).then(() => { console.log(3) })
.then(() => { console.log(4) })
.then(() => { console.log(6) })
Why does the code will run in different order? (that two data)
await with function will print 1,2,3,4,5,6
await with expression will print 1,2,3,5,4,6