JavaScript MCQ Practice Questions and Answers for Beginners
JavaScript is an essential programming language for modern web development. These 20 multiple-choice questions help BCA, BTech and other computer science students revise JavaScript fundamentals before examinations, interviews and practical assessments.
Try answering each question before checking the explanation.
JavaScript Fundamentals
1. Which keyword declares a block-scoped variable?
A. var B. let C. define D. global
Answer: B. let.
Explanation: Variables declared using let have block scope. The const keyword also creates block-scoped bindings but does not allow reassignment.
2. Which operator checks strict equality?
A. = B. == C. === D. !=
Answer: C. ===.
Explanation: Strict equality compares values without performing type coercion.
Example:
console.log(5 === "5"); // false
console.log(5 === 5); // true
3. What is the result of typeof null?
A. null B. object C. undefined D. boolean
Answer: B. object.
Explanation: This is a longstanding historical behavior of JavaScript. Although typeof null returns object, null is a primitive value.
4. Which method converts a JSON string into a JavaScript value?
A. JSON.stringify() B. JSON.parse() C. JSON.convert() D. JSON.decode()
Answer: B. JSON.parse().
Explanation: JSON.parse converts valid JSON text into the corresponding JavaScript value. JSON.stringify performs the reverse operation.
5. Which value is falsy?
A. [] B. {} C. "0" D. 0
Answer: D. 0.
Explanation: The number zero is falsy. Empty arrays, empty objects and nonempty strings are truthy.
Arrays and Objects
6. Which method adds an element to the end of an array?
A. push() B. pop() C. shift() D. slice()
Answer: A. push().
Explanation: push modifies the original array and returns its new length.
7. Which method creates a new array by transforming each element?
A. forEach() B. map() C. push() D. sort()
Answer: B. map().
Explanation: map returns a new array containing the result of applying a callback to every element.
8. What does Array.isArray([]) return?
A. false B. undefined C. true D. null
Answer: C. true.
Explanation: Array.isArray is the recommended way to check whether a value is an array.
9. Which syntax accesses the name property of an object?
A. user-name B. user.name C. user->name D. user::name
Answer: B. user.name.
Explanation: Dot notation accesses a named property. Bracket notation, such as user["name"], is another valid approach.
10. What does the spread syntax do in an array literal?
A. Deletes all elements B. Expands an iterable into individual elements C. Sorts elements automatically D. Converts every element to a string
Answer: B. Expands an iterable into individual elements.
Example:
const first = [1, 2];
const combined = [...first, 3];
The combined array contains 1, 2 and 3.
Functions and Scope
11. Which keyword is used to return a value from a function?
A. send B. return C. output D. break
Answer: B. return.
Explanation: The return statement ends function execution and provides a result to the caller.
12. What is a callback function?
A. A function passed to another function B. A function that always runs twice C. A function without parameters D. A function that cannot return a value
Answer: A. A function passed to another function.
Explanation: Callbacks are frequently used with array methods, events and asynchronous operations.
13. Which statement about const is correct?
A. It creates a function-scoped variable B. Its binding cannot be reassigned C. It makes every object property immutable D. It must contain a number
Answer: B. Its binding cannot be reassigned.
Explanation: const prevents reassignment of the binding, but properties of a referenced object may still be modified.
14. What is a closure?
A. A function with no body B. A function that retains access to its surrounding lexical environment C. A method for closing browser tabs D. A special HTML tag
Answer: B. A function that retains access to its surrounding lexical environment.
Explanation: Closures allow functions to use variables from the scope in which they were created, even after that outer function has finished.
DOM and Browser
15. Which method selects an element by its ID?
A. document.getElementById() B. document.findId() C. document.selectId() D. window.getId()
Answer: A. document.getElementById().
Explanation: This method returns the matching element or null when no element has the specified ID.
16. Which method registers an event handler?
A. attachHTML() B. addEventListener() C. registerCSS() D. createHandler()
Answer: B. addEventListener().
Example:
document.querySelector("button")
.addEventListener("click", () => {
console.log("Button clicked");
});
17. Which property changes an element's text without parsing HTML?
A. innerHTML B. textContent C. outerHTML D. tagName
Answer: B. textContent.
Explanation: textContent treats supplied content as text. It is often safer than innerHTML when displaying untrusted strings.
Asynchronous JavaScript
18. What does an async function return?
A. A Promise B. Always a string C. Always undefined D. An HTML element
Answer: A. A Promise.
Explanation: An async function returns a Promise, even when its return statement contains an ordinary value.
19. What is the purpose of await?
A. To permanently stop JavaScript execution B. To wait for a Promise to settle inside an allowed context C. To declare a global variable D. To convert a string to a number
Answer: B. To wait for a Promise to settle inside an allowed context.
Explanation: await pauses execution of the surrounding async function until the awaited value is resolved or rejected. It is also supported in top-level module contexts.
20. Which API is commonly used to make HTTP requests in modern browsers?
A. fetch() B. print() C. alert() D. prompt()
Answer: A. fetch().
Explanation: The Fetch API provides a Promise-based interface for HTTP requests and responses.
Example:
async function loadData() {
const response = await fetch("/api/items");
if (!response.ok) {
throw new Error("Request failed");
}
return response.json();
}
How to Practice JavaScript MCQs Effectively
Start by answering all 20 questions without checking the solutions. Review incorrect answers and run the related code examples in your browser developer tools or a local JavaScript environment.
Next, write small programs using arrays, objects, functions, DOM events and asynchronous requests. Practical exercises help you understand why each answer is correct.
For college examinations, revise the difference between var, let and const, equality operators, scope, closures, array methods and Promises.
Frequently Asked Questions
Are JavaScript MCQs useful for fresher interviews?
Yes. They help revise fundamentals, but interviews may also require live coding, debugging and project discussions.
What should beginners learn before JavaScript?
Basic HTML and CSS knowledge is useful for browser-based JavaScript development.
Is JavaScript the same as Java?
No. JavaScript and Java are different programming languages with different language designs and ecosystems.
How many questions should I practice daily?
Practicing 10 to 20 questions alongside short coding exercises is a reasonable starting routine.
Conclusion
JavaScript MCQs are useful for checking your understanding of syntax, data types, functions, arrays, DOM manipulation and asynchronous programming. Combine quiz practice with small projects to build practical programming skills.