Interview Q&A / JavaScript
JavaScript interview questions
Closures, the event loop, this, promises and the core language questions every frontend round asks.
Prefer rapid revision? Practise JavaScript short interview answers →
- What is the difference between promises and async/await, and how do you handle errors with each?
async/await is cleaner syntax built on top of promises. An async function always returns a promise, and await pauses that function until a promise settles. With promises you handle errors using .catch(); with async/await you use try/catch around the await.
BeginnerIn-depth3 min read - What are the states of a Promise, and what happens if you resolve it twice?
A promise is pending, then becomes fulfilled with a value or rejected with a reason. Once settled it never changes, so later resolve or reject calls are ignored.
BeginnerQuick answer1 min read - What does an async function return?
Always a Promise. A returned value becomes the fulfilled value, and a thrown error becomes a rejection. That is true even when the function contains no await.
BeginnerQuick answer1 min read