Review Questions


Questions in this sections are intended to give you a better understanding. I'm posting them here with the assumption that you will do your own research in figuring them out, and discuss with each other when you encounter a problem. The objective for you is not only to find the right answer, but to understand why.

1. What is the expected output?

When we run the following code, what do you think will be the precedence in the output window? Review the concepts of event loops, micro & macro tasks to answer this question.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/467c6a0c-cddf-4561-8751-09a7477f8a5e/carbon.png

2. Blocking Main Thread — Synchronous

Consider the code fragment below. What do you think will be the output when the code runs?

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/064fea56-4b4d-4d72-a109-4ec6adbf571c/carbon_(4).png

3. Blocking Main Thread — Messing up Promises

Consider the code fragment below. What do you think will be the output when the code runs?

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/900a7023-4b8d-4689-a879-85a9e5a3e42a/carbon_(3).png

Tip: The actual creation of the promise and the big while loop still happens on the main thread, only the resolution happens as a micro-task

4. Blocking Main Thread — Promises

Consider the code fragment below. What do you think will be the output when the code runs?

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/f86645ee-c95e-450c-8fd6-2c4d874fe73c/carbon_(5).png