This JavaScript basics MCQ quiz has a pool of 25 questions on variables, data types and the difference between let, const and var. It is made for freshers and computer students preparing for their first JavaScript interview. Every attempt gives you 10 random questions from the pool. Answer them, press Submit, and you will see your score, which answers were right or wrong, and a short explanation for each one.
Most questions ask “What is the output of this code?”, because that is how interviewers usually test the basics. Take the quiz again to get a new set of 10. If you want to revise first, read the key points below the quiz.
Take the JavaScript Basics MCQ Quiz
What This Quiz Covers
Every question comes from three topics that appear in almost every JavaScript fresher interview:
- Variables: how to declare them, naming rules, and what an uninitialised variable holds.
- Data types: the 7 primitive types, objects, and the
typeofoperator, including its famous surprises. - let, const and var: scope, hoisting, the temporal dead zone, redeclaring and reassigning.
JavaScript has 7 primitive data types: string, number, bigint, boolean, undefined, symbol and null. Everything else, including arrays and functions, is an object. Keep this list in mind, because several questions in the quiz depend on it.
Difference Between var, let and const
Most mistakes in a JavaScript basics MCQ test come from mixing up these three keywords. This table shows the four differences interviewers ask about.
| Feature | var | let | const |
|---|---|---|---|
| Scope | Function | Block | Block |
| Can be reassigned | Yes | Yes | No |
| Can be redeclared in the same scope | Yes | No | No |
| Use before the declaration line | Gives undefined | ReferenceError | ReferenceError |
| Must be given a value when declared | No | No | Yes |
A simple rule for real projects: use const by default, use let when the value has to change, and avoid var in new code. You can read the full rules for let on MDN, the standard JavaScript reference.
JavaScript Basics: Key Points to Revise
These short notes cover everything the quiz tests. They do not give away the quiz answers, but if you understand them, you can answer every question. The correct answers and explanations appear after you submit the quiz.
Naming rules for variables
A variable name can contain letters, digits, _ and $, but it cannot start with a digit. Names are case-sensitive, so total and Total are two different variables. Reserved words such as class, return and let cannot be used as names.
Primitive values and objects
Primitive values (string, number, bigint, boolean, undefined, symbol and null) are copied by value. Objects, arrays and functions are copied by reference, so two variables can point to the same object.
let p = 1;
let q = p; // q gets its own copy of 1
let o1 = { k: 1 };
let o2 = o1; // o2 points to the same object as o1The typeof operator
typeof returns a string that names the type of a value, such as "string", "number" or "boolean". Watch for its special cases: it has one answer for null that surprises most students, it treats functions differently from other objects, and it does not throw an error for a name that was never declared. A number written with an n at the end, like 7n, is a BigInt.
Hoisting and the temporal dead zone
JavaScript moves declarations to the top of their scope before running the code. This is called hoisting. A hoisted var starts with the value undefined. A hoisted let or const is not initialised, so the time between the start of the block and the declaration line is the “temporal dead zone”.
Scope of var, let and const
var belongs to the whole function it is written in and ignores if and loop blocks. let and const belong only to the nearest pair of curly braces. At the top level of a browser script, only var creates a property on window.
What const really protects
const stops the variable from being given a new value, and it must get its value on the same line. It does not lock the object or array it holds, so you can still change their contents. Use Object.freeze() if you need a locked object.
How to Score Better Next Time
- Run every code question yourself in the browser console (press F12 and open the Console tab).
- Read the explanation of every question you got wrong on the result page, then retake the quiz.
- Learn the var, let and const table above by heart. It answers many of the questions in this quiz.
If you are also preparing web basics for the same interview, try our HTML MCQ questions, and if your company asks backend questions too, practise with the PHP MCQ questions with answers.
Frequently Asked Questions
Is this JavaScript quiz good for freshers?
Yes. It covers only the basics that every fresher JavaScript interview starts with: variables, data types and let, const and var. You do not need to know functions or the DOM for this quiz.
Should I use var, let or const?
Use const by default and let when the value must change. Avoid var in new code, because its function scope and hoisting cause bugs that let and const prevent.
Where can I see the correct answers?
Press Submit at the end of the quiz. The result page shows your score, the correct answer for every question and a short explanation. The answers are not listed on this page so that you test yourself first.
Conclusion
This JavaScript basics MCQ quiz tested the three topics that start almost every JavaScript interview: variables, data types and the difference between var, let and const. If you scored 8 or more out of 10, retake the quiz once or twice to see new questions from the pool of 25. If not, read the key points again, run the code in your browser console, and try again.
Get one new quiz every week. Join Quiz Lancer on Telegram →
Full-stack developer with 5+ years of experience in PHP, Laravel and JavaScript. I create these quizzes to help students and freshers prepare for web development interviews.


