foo() {
console.log(2);
setTimeout(() => {
console.log('v');
});
}
async function bar() {
console.log(3);
await foo();
console.log(4);
}
bar();
console.log(5);
// 1
// s
// 3
// 2
// 5
// 4
// v
Guys, can someone explain why the console.log(2) inside foo is executed instantly, shouldn’t it be asynchronous(microtask) because of the await?
if you wanna delay then shouldnt console.log(2) be inside setTimeout?
Обсуждают сегодня