Member-only story
Javascript Interview: 5 promise questions you can see in your interview
Published in
3 min readJan 6, 2025

1. Guess the output
new Promise((resolve, reject) => {
resolve(1)
resolve(2)
reject('error')
}).then((value) => {
console.log(value)
}, (error) => {
console.log('error')
})
Answer: 1
Explaination:
When the new promise is created, it is immediately resolved with the value 1
in the first resolve(1)
statement. Although resolve(2)
and reject('error')
are called afterward, they are ignored because a promise can only be settled once. Since the promise resolves with 1
, the .then()
method's success callback is triggered, logging 1
. The rejection callback (error
) is never called, as the promise was already resolved.
2. Guess the output
console.log(1)
const promise = new Promise((resolve) => {
console.log(2)
resolve()
console.log(3)
})
console.log(4)
promise.then(() => {
console.log(5)
}).then(() => {
console.log(6)
})
console.log(7)
setTimeout(() => {
console.log(8)
}, 10)
setTimeout(() => {
console.log(9)
}, 0)
Answer: 1 2 3 4 7 5 6 9 8
Explaination:
console.log(1)
prints1
.- The promise constructor runs, logging
2
, then resolves, logging3
.