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
- JavaScript Introduction
- Where to Put JavaScript
- JavaScript Output (console.log)
- JavaScript Variables (let and const)
- JavaScript Data Types
- JavaScript Operators
- JavaScript Strings
- JavaScript Numbers
- JavaScript If/Else
- JavaScript Switch
- JavaScript Loops (for, while)
- JavaScript Arrays
- JavaScript Array Methods
- JavaScript Objects
- JavaScript Functions
- JavaScript Arrow Functions
- JavaScript Scope
- DOM: Selecting Elements
- DOM: Changing Content
- JavaScript Events
- JavaScript Forms and Validation
- JavaScript Local Storage
- JavaScript Fetch and JSON
- JavaScript Async/Await
- JavaScript Project: To-Do List App
Sample questions with answers
1. Is JavaScript the same as Java?
- Yes
- JavaScript is Java for browsers
- 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?
- Never runs the script
- Downloads in parallel and runs after the HTML is parsed, in order
- 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?
- alert()
- console.log()
- 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?
- let
- const
- var
Show answer
B. const — Use const by default, let when it changes.
5. What does typeof null return?
- "object"
- "undefined"
- "null"
Show answer
A. "object" — A long-standing JavaScript quirk.
6. Why prefer === over ==?
- === compares without type conversion
- == is deprecated
- === 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?
- "Hel"
- "el"
- "ell"
Show answer
B. "el" — The end index is excluded.
8. What does 0.1 + 0.2 === 0.3 return?
- true
- NaN
- false
Show answer
C. false — Binary floating point can't represent these exactly.
9. What are guard clauses?
- Early returns that handle special cases first, avoiding deep nesting
- Security checks
- 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?
- Strict equality (===)
- Loose equality (==)
- Regex
Show answer
A. Strict equality (===) — "1" won't match case 1.