DEV Community

Cover image for JavaScript Interview Question #25: Immediate Promise.resolve
Coderslang: Become a Software Engineer
Coderslang: Become a Software Engineer

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

JavaScript Interview Question #25: Immediate Promise.resolve

js-test-25

How fast is Promise.resolve() in JavaScript? Which of the messages will be logged first?

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

The logic is almost the same as in this setTimeout example.

If you're new to the JS Promises, I suggest starting here:

Even though Promise.resolve() doesn’t have any explicit delay, the code inside of .then() is executed asynchronously and has a lower priority than the synchronous code.

So, the console.log('resolved') will be executed after the console.log('end').


ANSWER: the string end will be logged first, followed up by resolved.

Learn Full Stack JavaScript

Top comments (0)