Промисы

Задача #1

Что будет в консоли и почему?

Promise.resolve(1)
    .then((x) => x + 1)
    .then((x) => {
        throw x;
    })
    .then((x) => console.log(x))
    .catch((err) => console.log(err))
    .then((x) => Promise.resolve(x))
    .catch((err) => console.log(err))
    .then((x) => console.log(x));

Задача #2

Что будет в консоли и почему?

async function test() {
    console.log(1);
    await Promise.resolve();
    console.log(2);
}
 
console.log(3);
test();
console.log(4);

См. также