Interview Q&A / JavaScript

INTERVIEW Q&A · 71 QUESTIONS

JavaScript interview questions

Closures, the event loop, this, promises and the core language questions every frontend round asks.

  1. 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
  2. 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
  3. 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