DEV Community

loading...
Cover image for JavaScript Interview Question #25: Immediate Promise.resolve

JavaScript Interview Question #25: Immediate Promise.resolve

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

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

Discussion (0)

Forem Open with the Forem app