All JavaScript quizzes
Intermediate30 questions40 minutes

JavaScript Intermediate Quiz

Scope, async behaviour, array methods and equality — the everyday JavaScript that decides whether code works or merely appears to.

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(a)
console.log(b)
var a = 1
let b = 2
  • A ReferenceError immediately
  • undefined then undefined
  • 1 then 2
  • undefined, then a ReferenceError
Show answer

Answer: undefined, then a ReferenceError. `var` declarations are hoisted and initialised to undefined, so the first log succeeds. `let` is hoisted too but sits in the temporal dead zone until its declaration runs, so reading it early throws. That difference is the main practical reason to prefer `let`.

2. What does this print?

const arr = [1, 2, 3]
const doubled = arr.map(n => n * 2)
const filtered = arr.filter(n => n > 1)
console.log(arr.length, doubled, filtered)
  • 3 [2, 4, 6] [1, 2, 3]
  • 3 [2, 4, 6] [2, 3]
  • 6 [2, 4, 6] [2, 3]
  • 3 [1, 2, 3] [2, 3]
Show answer

Answer: 3 [2, 4, 6] [2, 3]. `map` and `filter` both return new arrays and leave the original untouched — `arr` still has 3 elements. Knowing which array methods mutate (push, sort, splice, reverse) and which do not is the difference between predictable and surprising code.

3. This should log each id after fetching, in order. Instead it logs nothing useful. Which line is wrong?

1  ids.forEach(async (id) => {
2    const user = await getUser(id)
3    console.log(user.name)
4  })
5  console.log('done')
  • Line 5 — it needs to be inside the callback
  • Line 2 — await cannot be used inside a callback
  • Line 3 — console.log must be awaited
  • Line 1 — forEach ignores the returned promises, so 'done' logs first and order is not guaranteed
Show answer

Answer: Line 1 — forEach ignores the returned promises, so 'done' logs first and order is not guaranteed. `forEach` discards whatever its callback returns, so it finishes immediately without waiting and 'done' prints before any user. Use `for (const id of ids) { await ... }` for sequential order, or `await Promise.all(ids.map(...))` to run them concurrently.

Frequently asked questions

How many questions are in this JavaScript quiz?+

30 questions, with a 40-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 intermediate quiz aimed at?+

Scope, async behaviour, array methods and equality — the everyday JavaScript that decides whether code works or merely appears to.

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?

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

Start now