如何在JavaScript中执行异步功能?

问题描述 投票:0回答:1

let x = 0;

async function test() {
    x += await 5;
    console.log('x :', x);
}

test();
x += 1;
console.log('x :', x);
记录的x的值为1和5。为什么在第二个日志中x的值为5?
javascript async-await event-loop
1个回答
0
投票

let x = 0;

async function test() {
    x += await 5;
    console.log('x :', x);
}

test();
x += 1;
console.log('y :', x);
© www.soinside.com 2019 - 2024. All rights reserved.