๐Ÿ‘ค My Profile (Player)๐Ÿ  Home๐Ÿ—‚๏ธ Categories๐ŸŽฎ Play Game Modes๐Ÿ‘‘ Live Party Room๐Ÿ—‚๏ธ Mistakes & Flashcardsโšก Flash Quiz Shorts๐Ÿ“‹ Quiz History๐Ÿ… Achievements๐Ÿ† Daily Challenge๐Ÿค– AI Generator๐Ÿ“ Quiz Blog
Programming ยท JavaScript

JavaScript Quiz: 20 Questions Developers Should Know

Sharpen your JavaScript for interviews with 20 core questions and answers covering closures, hoisting, the event loop, promises, "this", and type coercion.

20 Questions12 min readPublished: July 15, 2026Updated: July 15, 2026
Play the Computer Science Quiz
Illustration of code braces in a glowing gold medallion, surrounded by code, terminal, bug and zap icons
Quick warm-up1 / 5

Can you get 5 out of 5?

What is the difference between `let`, `const`, and `var`?

Think of your answer, then reveal it to check.

How Well Do You Know JavaScript?

Think of your answer to each question, reveal the real one with a short explanation, and mark whether you knew it to build your score. Then keep going in the full interactive quiz.

20 questionsAnswers explainedFree ยท No sign-up
Play the Computer Science Quiz

Introduction

JavaScript powers almost every website on the planet, which makes it one of the most tested topics in technical interviews. The tricky part is that JavaScript has quirks (hoisting, coercion, the event loop) that trip up even experienced developers.

Below are 20 JavaScript quiz questions with clear answers and short explanations. Read through them to revise, then jump into the interactive quiz to test what stuck.

Core Concepts (Questions 1โ€“10)

Q1
1 / 10

What is the difference between `let`, `const`, and `var`?

Think of your answer, then reveal it to check.

Show all 10 questions and answers
  1. What is the difference between `let`, `const`, and `var`?

    Answer: `var` is function-scoped and hoisted; `let` and `const` are block-scoped. `const` cannot be reassigned.

    `var` declarations are hoisted and initialised as `undefined`. `let` and `const` are hoisted too but sit in the "temporal dead zone" until the declaration line, so accessing them early throws a ReferenceError.

  2. What is a closure?

    Answer: A function that remembers the variables from the scope where it was created, even after that scope has returned.

    Closures let inner functions keep access to outer variables. They power data privacy, function factories, and memoisation.

  3. What does `typeof null` return?

    Answer: 'object'

    This is a long-standing bug in JavaScript kept for backward compatibility. `null` is a primitive, but `typeof null` still returns "object".

  4. What is the output of `0.1 + 0.2 === 0.3`?

    Answer: false

    Floating-point numbers cannot represent 0.1 and 0.2 exactly, so the sum is 0.30000000000000004. Compare with a small epsilon instead of `===`.

  5. What is hoisting?

    Answer: JavaScript moving declarations to the top of their scope before execution.

    Function declarations are fully hoisted (callable before they appear). `var` is hoisted as `undefined`. `let`/`const` are hoisted but not initialised.

  6. What is the difference between `==` and `===`?

    Answer: `==` compares after type coercion; `===` compares value and type with no coercion.

    `0 == "0"` is true but `0 === "0"` is false. Prefer `===` to avoid surprising coercion bugs.

  7. What does `this` refer to inside a regular function called on its own?

    Answer: The global object (or `undefined` in strict mode).

    The value of `this` depends on how a function is called, not where it is defined. Arrow functions instead inherit `this` from the enclosing scope.

  8. What is the difference between `null` and `undefined`?

    Answer: `undefined` means a variable has not been assigned; `null` is an intentional "no value".

    `undefined` is the default for uninitialised variables and missing properties. `null` is a value you assign deliberately.

  9. What is the result of `[] + []`?

    Answer: An empty string ""

    The `+` operator converts both arrays to primitives. An empty array becomes an empty string, so `"" + "" === ""`.

  10. What is the difference between `map()` and `forEach()`?

    Answer: `map()` returns a new array; `forEach()` returns undefined.

    Use `map()` when you want a transformed array. Use `forEach()` for side effects where you do not need a return value.

Interview tip

When asked about `this`, always clarify *how* the function is called (method, standalone, arrow, or bound). That single distinction answers most `this` questions.

Async & Advanced (Questions 11โ€“20)

Q11
1 / 10

What is the event loop?

Think of your answer, then reveal it to check.

Show all 10 questions and answers
  1. What is the event loop?

    Answer: The mechanism that lets single-threaded JavaScript handle async work by moving completed callbacks from queues onto the call stack.

    When the call stack is empty, the event loop pushes queued callbacks (from timers, promises, events) onto it, one at a time.

  2. What is the difference between microtasks and macrotasks?

    Answer: Promises use the microtask queue, which runs before the macrotask queue (setTimeout, setInterval).

    After each task, all pending microtasks drain before the next macrotask runs, which is why a resolved promise callback fires before a `setTimeout(โ€ฆ, 0)`.

  3. What is a Promise?

    Answer: An object representing the eventual result of an async operation, with states pending, fulfilled, or rejected.

    Promises replace callback nesting with `.then()`/`.catch()` chains and are the foundation for `async`/`await`.

  4. What does `async`/`await` do?

    Answer: `async` marks a function that returns a promise; `await` pauses it until a promise settles.

    `await` makes async code read like synchronous code. Wrap awaits in `try/catch` to handle rejections.

  5. What is the difference between `Promise.all` and `Promise.race`?

    Answer: `all` waits for every promise (or the first rejection); `race` settles as soon as the first promise settles.

    Use `Promise.all` for parallel work you all need; use `Promise.race` for timeouts or "first response wins" logic.

  6. What is event delegation?

    Answer: Attaching one listener to a parent element to handle events from many children via bubbling.

    Delegation improves performance and works for elements added later, since the parent catches events that bubble up.

  7. What is the difference between shallow copy and deep copy?

    Answer: A shallow copy duplicates top-level values only; a deep copy duplicates nested objects too.

    The spread operator and `Object.assign` are shallow. Use `structuredClone(obj)` for a true deep copy of most values.

  8. What does the spread operator `...` do?

    Answer: Expands an iterable into individual elements (arrays, function args) or copies object properties.

    `[...arr]` copies an array, `{...obj}` copies an object, and `fn(...args)` spreads arguments into a call.

  9. What is debouncing?

    Answer: Delaying a function until a pause in rapid events, so it runs only once after activity stops.

    Debouncing is common for search inputs and resize handlers to avoid firing on every keystroke or pixel.

  10. What is the temporal dead zone (TDZ)?

    Answer: The period between entering a scope and a `let`/`const` declaration, during which the variable cannot be accessed.

    Referencing a `let`/`const` variable in its TDZ throws a ReferenceError, unlike `var` which returns `undefined`.

Common mistake

Do not compare floating-point numbers with `===`. Use `Math.abs(a - b) < Number.EPSILON` instead.

Ready for More JavaScript Questions?

Play the full interactive quiz with timed rounds, instant scoring and explanations for every answer.

Play the Computer Science Quiz

More Quizzes You'll Enjoy

Related Articles

Frequently Asked Questions