DEV Community

loading...
Cover image for JavaScript Interview Question #28: Resolve and reject at the same time

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

coderslang profile image Coderslang: Become a Software Engineer Originally published at learn.coderslang.com on ・1 min read

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

Discussion (2)

pic
Editor guide
Collapse
devlorenzo profile image
DevLorenzo

Carbon is a really nice app 😃

Collapse
coderslang profile image