JobsPing

JavaScript interview practice

Covers closures, the event loop, prototypes, async/await, ES modules. Questions are written for real interviews at junior, mid and senior level.

Start a JavaScript practice test

15 multiple-choice questions · 15 minutes · instant score with explanations

Sample JavaScript interview questions

Three questions from the bank, with answers. The practice test draws different ones each time.

Question 1 · event loop · mid

What is the correct output sequence of the queued operations?

queueMicrotask(() => console.log('Microtask 1'));
Promise.resolve().then(() => {
  console.log('Promise 1');
  queueMicrotask(() => console.log('Microtask 2'));
});
setTimeout(() => console.log('Timeout'), 0);
  1. A.Microtask 1, Promise 1, Timeout, Microtask 2
  2. B.Microtask 1, Microtask 2, Promise 1, Timeout
  3. C.Microtask 1, Promise 1, Microtask 2, Timeout
  4. D.Timeout, Microtask 1, Promise 1, Microtask 2
Show answer

C. Microtask 1, Promise 1, Microtask 2, Timeout

queueMicrotask and Promise.then both queue callbacks onto the microtask queue. Microtask 1 and Promise 1 run first; during Promise 1 execution, Microtask 2 is appended to the microtask queue. The event loop continuously drains all microtasks (including Microtask 2) before moving to the macrotask queue for Timeout.

Question 2 · async/await · mid

How does await handle a promise rejection inside an async function without a try/catch block?

async function fetchData() {
  const result = await Promise.reject(new Error('Failed'));
  return result;
}
fetchData().catch(err => console.log(err.message));
  1. A.await throws the rejected value, causing the returned promise of fetchData to reject.
  2. B.await converts the rejection into a synchronous warning and returns null.
  3. C.The program crashes instantly without returning a promise.
  4. D.await returns undefined and continues execution to the return statement.
Show answer

A. await throws the rejected value, causing the returned promise of fetchData to reject.

When an awaited promise rejects, await unwraps the rejection and throws it as a Javascript error inside the async function. Without a try/catch block, this uncaught thrown error causes the promise returned by fetchData() to reject. Developers often mistakenly think await returns undefined or null on rejection.

Question 3 · prototypes · mid

What is the result of checking instanceof for c against Child and Parent?

function Parent() {}
function Child() {}
Child.prototype = Object.create(Parent.prototype);
const c = new Child();

console.log(c instanceof Child, c instanceof Parent);
  1. A.true true
  2. B.false false
  3. C.false true
  4. D.true false
Show answer

A. true true

The instanceof operator checks if a constructor's prototype property exists anywhere along an object's prototype chain. Because Child.prototype was assigned an object linked to Parent.prototype via Object.create, instance c inherits from both Child.prototype and Parent.prototype, making both checks true.

Ready to apply? Browse remote JavaScript jobs →