DEV Community

Cover image for JavaScript Interview Question #28: Resolve and reject at the same time
Coderslang: Become a Software Engineer
Coderslang: Become a Software Engineer

Posted on • Originally published at learn.coderslang.com on

JavaScript Interview Question #28: Resolve and reject at the same time

js-test-28

Can you resolve and reject the JS Promise at the same time? What will be printed to the console?

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

In JavaScript, promises can’t be resolved and rejected at the same time.

The execution will never reach the call to setTimeout and thus reject(2), inside of it.

Thus only the number 1 will be printed on the screen.


ANSWER: A single message will be logged to the console. After the promise is resolved with 1 the execution stops and the setTimeout won’t be called.

Learn Full Stack JavaScript

Top comments (2)

Collapse
 
lorenzoblog profile image
Lorenzo

Carbon is a really nice app 😃

Collapse
 
coderslang profile image
Coderslang: Become a Software Engineer

100%