Learn. Practice. Feel prepared.
JavaScript Objective Questions and Answers - Set 3
This JavaScript quiz contains carefully curated objective questions with correct answers and clear explanations. It is designed for frontend and backend developers, interview preparation, and deep understanding of modern JavaScript concepts including ES6+, asynchronous behavior, scope, closures, and performance pitfalls. This is part 3 of the series.
Practice JavaScript MCQs with Detailed Explanations
Answer at least 12 questions to submit and verify answers.
31 What will be logged? console.log(typeof undefined == typeof null); Medium
Correct answer:
true
Both typeof expressions return 'undefined' and 'object', comparison is false - but == compares booleans after evaluation.
32 Which pattern helps prevent memory leaks with event listeners? High
Correct answer:
Removing listeners explicitly
Event listeners should be removed when no longer needed.
33 What does Promise.all() do if one Promise rejects? High
Correct answer:
Rejects immediately
Promise.all rejects immediately when any Promise rejects.
34 Which scenario creates a closure? Medium
Correct answer:
Returning a function
Returning a function preserves access to its lexical scope.
35 What is the output? console.log(+true); Medium
Correct answer:
1
Unary plus converts true to number 1.
36 Which statement about async/await is true? High
Correct answer:
await pauses only the async function
await pauses execution only within the async function.
37 What is the output? console.log([] === []); Medium
Correct answer:
false
Arrays are compared by reference, not by value.
38 Which structure is most likely to cause a memory leak? High
Correct answer:
Detached DOM references
Detached DOM references prevent garbage collection.
39 What does the call stack manage? Medium
Correct answer:
Function execution order
The call stack tracks function calls and execution order.
40 Which operation is synchronous? Medium
Correct answer:
Array.map
Array.map executes synchronously.
41 What will be logged? console.log(typeof function(){}); Medium
Correct answer:
function
Functions have type 'function' in JavaScript.
42 Which can prevent accidental global variables? Medium
Correct answer:
use strict
Strict mode prevents implicit global variable creation.
43 What happens if await is used outside async? Medium
Correct answer:
SyntaxError
await can only be used inside async functions.
44 What is the output? console.log(null + 1); Medium
Correct answer:
1
null is coerced to 0 in numeric context.
45 Which tool helps avoid memory leaks in key-value storage? High
Correct answer:
WeakMap
WeakMap allows garbage collection of unused keys.