While it's true that a Promise starts executing immediately upon creation, it's important to clarify that the execution happens asynchronously. The term "eager" can be misleading because it implies that the Promise blocks the main thread, but that's not the case. Promises do not block the main thread; they begin execution as soon as they are created, but they resolve asynchronously—meaning the callback functions (.then(), .catch(), etc.) are queued to run later when the JavaScript event loop is free.
In this case, the Promise starts executing as soon as it’s created, but the resolve() function waits for 1 second before returning the value asynchronously.
Passionate and detail-oriented Frontend Developer with 15 years of experience in building responsive, user-friendly web applications. Proficient in HTML, CSS, JavaScript, and modern frameworks like Re
Thank you for your insightful comment! You are absolutely correct that Promises in JavaScript start executing immediately upon creation, but they do so asynchronously.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
While it's true that a Promise starts executing immediately upon creation, it's important to clarify that the execution happens asynchronously. The term "eager" can be misleading because it implies that the Promise blocks the main thread, but that's not the case. Promises do not block the main thread; they begin execution as soon as they are created, but they resolve asynchronously—meaning the callback functions (
.then(),.catch(), etc.) are queued to run later when the JavaScript event loop is free.For example:
In this case, the Promise starts executing as soon as it’s created, but the
resolve()function waits for 1 second before returning the value asynchronously.Thank you for your insightful comment! You are absolutely correct that Promises in JavaScript start executing immediately upon creation, but they do so asynchronously.