Created
August 23, 2024 13:56
-
-
Save carefree-ladka/1a6eb9a803721db192f096dc68488691 to your computer and use it in GitHub Desktop.
Tricky Event Loop Based Question
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| console.log('Start'); | |
| setTimeout(() => { | |
| console.log('Inside setTimeout'); | |
| }, 0); | |
| Promise.resolve() | |
| .then(() => { | |
| console.log('Inside first promise'); | |
| return new Promise((resolve) => { | |
| setTimeout(() => { | |
| console.log('Inside promise-setTimeout'); | |
| resolve(); | |
| }, 0); | |
| }); | |
| }) | |
| .then(() => { | |
| console.log('Inside second promise'); | |
| }); | |
| setTimeout(() => { | |
| console.log('Inside second setTimeout'); | |
| Promise.resolve().then(() => { | |
| console.log('Inside promise within setTimeout'); | |
| }); | |
| }, 0); | |
| console.log('End'); | |
| /* | |
| Start | |
| End | |
| Inside first promise | |
| Inside setTimeout | |
| Inside second setTimeout | |
| Inside promise within setTimeout | |
| Inside promise-setTimeout | |
| Inside second promise | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment