Promises in JavaScript: What Interviewers Actually Ask.
“So, what’s a Promise in JavaScript?” Easy… until they keep digging. Here’s the short list of what you really need to know when this comes up.
The Basics
Core Methods
Example:
fetch('/api')
.then(res => res.json())
.catch(err => console.error(err))
.finally(() => console.log('Done'));
Callback vs Promise vs Async/Await
Callbacks (the old way):
getUser(1, (err, user) => {
if (err) return console.error(err);
getPosts(user.id, (err, posts) => {
if (err) return console.error(err);
getComments(posts[0].id, (err, comments) => {
if (err) return console.error(err);
console.log(comments);
});
});
});
Problems: callback hell, messy error handling, hard composition.
Promises:
getUser(1)
.then(user => getPosts(user.id))
.then(posts => getComments(posts[0].id))
.then(comments => console.log(comments))
.catch(err => console.error(err));
Cleaner chains, one catch, easier to reason about.
Async/Await (syntactic sugar on top of Promises):
async function main() {
try {
const user = await getUser(1);
const posts = await getPosts(user.id);
const comments = await getComments(posts[0].id);
console.log(comments);
} catch (err) {
console.error(err);
}
}
Looks synchronous, keeps error handling consistent, still powered by Promises.
Common Interview Questions
What’s the difference between microtasks and macrotasks?
Parallel execution?
Recommended by LinkedIn
What does .then return?
Promise.resolve(1)
.then(x => x + 1) // returns Promise<2>
.then(x => x * 2) // returns Promise<4>
The Tricky One
What’s the output?
console.log('A');
setTimeout(() => console.log('B'), 0);
Promise.resolve()
.then(() => {
console.log('C');
return Promise.resolve('D');
})
.then((val) => console.log(val));
queueMicrotask(() => {
console.log('E');
Promise.resolve().then(() => console.log('F'));
});
console.log('G');
👉 Answer: A, G, C, E, D, F, B.
2. Drain microtasks (FIFO)
3. Next macrotask
Key Takeaways
TL;DR
Promises aren’t just about .then vs .catch. They’re about chaining, error handling, and execution order. Learn those → you’ve answered 90% of interview questions.
Question: which Promise utility (all, any, race, allSettled) has saved you the most in production?
This is Part 2 of 17 in my Frontend Interview Classics series.