All JavaScript quizzes
Expert16 questions30 minutes

JavaScript Expert Quiz

Event loop ordering, closures, coercion and prototypes — the questions that actually separate senior candidates in a technical screen.

Start the quiz

Sample questions from this quiz

A preview of the style and depth. Try each one, then reveal the answer — or skip straight to the timed quiz.

1. What does this print?

console.log('1')
setTimeout(() => console.log('2'), 0)
Promise.resolve().then(() => console.log('3'))
console.log('4')
  • 1 4 2 3
  • 1 4 3 2
  • 1 2 3 4
  • 1 3 4 2
Show answer

Answer: 1 4 3 2. Synchronous code runs first, so 1 and 4 print immediately. Then the microtask queue drains before the macrotask queue, so the resolved Promise callback (3) runs before the setTimeout callback (2) — even with a 0 ms delay. Microtasks always win.

2. What does this print?

for (var i = 0; i < 3; i++) {
  setTimeout(() => console.log(i), 0)
}
  • 0 1 2
  • 3 3 3
  • 0 0 0
  • undefined undefined undefined
Show answer

Answer: 3 3 3. `var` is function-scoped, so all three callbacks close over the same binding. By the time the timeouts fire the loop has finished and `i` is 3. Swapping `var` for `let` creates a fresh binding per iteration and prints 0 1 2.

3. This function should return the total of all prices. Which line causes it to return a Promise instead of a number?

1  async function total(ids) {
2    const items = await Promise.all(ids.map(fetchItem))
3    const sum = items.reduce(async (acc, item) => {
4      return (await acc) + item.price
5    }, 0)
6    return sum
7  }
  • Line 3 — an async reducer makes the accumulator a Promise
  • Line 2 — Promise.all should not be awaited here
  • Line 4 — awaiting the accumulator is invalid syntax
  • Line 6 — sum needs to be awaited before returning
Show answer

Answer: Line 3 — an async reducer makes the accumulator a Promise. An `async` callback always returns a Promise, so `reduce` produces a Promise as its accumulator on every pass. The code happens to still work if you await the result, but `sum` is a Promise, not a number. Since the items are already resolved by line 2, the reducer should be synchronous: `items.reduce((acc, item) => acc + item.price, 0)`.

Frequently asked questions

How many questions are in this JavaScript quiz?+

16 questions, with a 30-minute time limit. Every question includes a written explanation of the correct answer.

Is this JavaScript quiz free?+

Yes. Every quiz on CodexQuizz is free and needs no account. You only enter a name if you choose to post your score to the leaderboard.

What level is the expert quiz aimed at?+

Event loop ordering, closures, coercion and prototypes — the questions that actually separate senior candidates in a technical screen.

Can I use this to prepare for a JavaScript interview?+

Yes. The questions cover the topics that come up in JavaScript technical screens, and the explanations are written so that a wrong answer still teaches you the underlying concept.

Ready to test your JavaScript?

16 questions, 30 minutes. Free, no sign-up.

Start now