Sobes.tech
Back to tasks
Junior — Senior
24

Что будет напечатано в консоли? (пример 32)

Get help with live coding in real time with Sobes Copilot
Task condition

Определите порядок вывода сообщений в консоль при выполнении приведённого кода.

import './style.css';

document.getElementById('app').innerHTML = '\
<h1>Async Puzzle</h1>\
';

const asyncFuncA = async () => {
    console.log('1', '?');
    setTimeout(() => console.log('2', '?'), 0);

    Promise.resolve().then(() => console.log('3', '?'));

    const asyncFuncB = async () => {
        setTimeout(() => console.log('4', '?'), 1);
        console.log('5', '?');
        Promise.resolve().then(() =>
            setTimeout(() => console.log('6', '?'), 0)
        );
    };

    const initPromise = new Promise((res) => {
        console.log('7', '?');
        [
            Promise.resolve().then(() => console.log('8', '?')),
            setTimeout(() => {
                res();
            },
            )
        ];
    });

    await initPromise;

    console.log('9', '?');
};

Promise.resolve().then(() => console.log('10', '?'));

await asyncFuncB();

console.log('11', '?');
};

asyncFuncA();

console.log('12', '?');