JavaScript MCQ Test

20 random JavaScript MCQs with answers: variables, types, functions, arrays, objects, the DOM, events, promises and async/await. Timed practice test with explanations.

  • 20 random questions
  • 20 minutes
  • 75 in the question bank

No sign-up needed. Answers and explanations are shown at the end.

About this test

JavaScript has more “what does this print?” traps than any other beginner language: type coercion, let vs const, scope, and asynchronous code. This test picks questions from all of them.

Each answer comes with a one-line explanation, so a wrong answer still teaches you something.

Each attempt picks new questions at random from the question bank. You can go back and change answers until you finish or the timer runs out. At the end you see your score, the right answer and a short explanation for every question, and the lessons to revise for the ones you missed.

Topics covered

  1. JavaScript Introduction
  2. Where to Put JavaScript
  3. JavaScript Output (console.log)
  4. JavaScript Variables (let and const)
  5. JavaScript Data Types
  6. JavaScript Operators
  7. JavaScript Strings
  8. JavaScript Numbers
  9. JavaScript If/Else
  10. JavaScript Switch
  11. JavaScript Loops (for, while)
  12. JavaScript Arrays
  13. JavaScript Array Methods
  14. JavaScript Objects
  15. JavaScript Functions
  16. JavaScript Arrow Functions
  17. JavaScript Scope
  18. DOM: Selecting Elements
  19. DOM: Changing Content
  20. JavaScript Events
  21. JavaScript Forms and Validation
  22. JavaScript Local Storage
  23. JavaScript Fetch and JSON
  24. JavaScript Async/Await
  25. JavaScript Project: To-Do List App

Sample questions with answers

1. Is JavaScript the same as Java?

  1. Yes
  2. JavaScript is Java for browsers
  3. No, they are different languages
Show answer

C. No, they are different languages — The names are similar for historical marketing reasons only.

2. What does defer do on a script tag?

  1. Never runs the script
  2. Downloads in parallel and runs after the HTML is parsed, in order
  3. Runs it before the page
Show answer

B. Downloads in parallel and runs after the HTML is parsed, in order — It's the modern best practice for external scripts.

3. What's the best tool for checking values while coding?

  1. alert()
  2. console.log()
  3. document.write()
Show answer

B. console.log() — Open DevTools' Console to see the output.

4. Which keyword declares a value that won't be reassigned?

  1. let
  2. const
  3. var
Show answer

B. const — Use const by default, let when it changes.

5. What does typeof null return?

  1. "object"
  2. "undefined"
  3. "null"
Show answer

A. "object" — A long-standing JavaScript quirk.

6. Why prefer === over ==?

  1. === compares without type conversion
  2. == is deprecated
  3. === is faster to type
Show answer

A. === compares without type conversion — 0 == "" is true; 0 === "" is false.

7. What does "Hello".slice(1, 3) return?

  1. "Hel"
  2. "el"
  3. "ell"
Show answer

B. "el" — The end index is excluded.

8. What does 0.1 + 0.2 === 0.3 return?

  1. true
  2. NaN
  3. false
Show answer

C. false — Binary floating point can't represent these exactly.

9. What are guard clauses?

  1. Early returns that handle special cases first, avoiding deep nesting
  2. Security checks
  3. Try/catch blocks
Show answer

A. Early returns that handle special cases first, avoiding deep nesting — They keep the main logic flat.

10. What does switch use to compare?

  1. Strict equality (===)
  2. Loose equality (==)
  3. Regex
Show answer

A. Strict equality (===) — "1" won't match case 1.