Skip to content

Instantly share code, notes, and snippets.

@mitoop
Created December 18, 2023 05:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mitoop/a3bc8fa50633c458702463b5b15d65a7 to your computer and use it in GitHub Desktop.
Save mitoop/a3bc8fa50633c458702463b5b15d65a7 to your computer and use it in GitHub Desktop.
Event Loop
console.log("1");

setTimeout(function () {
    console.log("2");
    new Promise(function (resolve) {
        console.log("3");
        resolve();
    }).then(function () {
        console.log("4");
    });

    setTimeout(function () {
        console.log("5");
        new Promise(function (resolve) {
            console.log("6");
            resolve();
        }).then(function () {
            console.log("7");
        });
    });
    console.log("14");
});

new Promise(function (resolve) {
    console.log("8");
    resolve();
}).then(function () {
    console.log("9");
});


setTimeout(function () {
    console.log("10");
    new Promise(function (resolve) {
        console.log("11");
        resolve();
    }).then(function () {
        console.log("12");
    });
});

console.log("13");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment