All JavaScript quizzes
Advanced30 questions45 minutes

JavaScript Advanced Quiz

Closures, prototypes, coercion and async behaviour — worked through code rather than definitions, the way a real technical screen does it.

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?

const obj = {
  name: 'outer',
  greet() {
    const inner = () => this.name
    return inner()
  }
}
console.log(obj.greet())
  • 'outer'
  • undefined
  • TypeError
  • 'inner'
Show answer

Answer: 'outer'. Arrow functions have no `this` of their own — they inherit it from the enclosing scope. `greet` is called as a method so its `this` is `obj`, and the arrow function inherits that. Had `inner` been a regular function, `this` would have been undefined in strict mode.

2. What does this print?

function counter() {
  let count = 0
  return { inc: () => ++count, get: () => count }
}
const a = counter()
const b = counter()
a.inc(); a.inc(); b.inc()
console.log(a.get(), b.get())
  • 3 3
  • 2 1
  • 2 2
  • 1 1
Show answer

Answer: 2 1. Each call to `counter()` creates a new scope, so `a` and `b` close over separate `count` bindings. This is the standard way to get private state in JavaScript — the variable is unreachable except through the returned functions.

3. This should debounce the handler, but it fires on every call. Which line is wrong?

1  function debounce(fn, wait) {
2    return function (...args) {
3      let timer
4      clearTimeout(timer)
5      timer = setTimeout(() => fn(...args), wait)
6    }
7  }
  • Line 2 — the returned function should be an arrow function
  • Line 4 — clearTimeout must come after setTimeout
  • Line 5 — the arrow function loses the arguments
  • Line 3 — timer is declared inside the returned function, so it resets each call
Show answer

Answer: Line 3 — timer is declared inside the returned function, so it resets each call. `timer` needs to live in the closure created by `debounce`, not inside the returned function. As written, every invocation gets a fresh `undefined` timer, so `clearTimeout` cancels nothing. Moving `let timer` to line 2's outer scope fixes it.

Frequently asked questions

How many questions are in this JavaScript quiz?+

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

Closures, prototypes, coercion and async behaviour — worked through code rather than definitions, the way a real technical screen does it.

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, 45 minutes. Free, no sign-up.

Start now