0

I've stumbled upon this question.

My instinct tells me the sum should be 3. Could someone explain what is actually happening?

let sum = 0;

async function add(num) {
    sum += await num;
}

add(1);
add(2);

setTimeout(() => console.log(sum), 100);
Hao Wu
  • 17,573
  • 6
  • 28
  • 60

0 Answers0