Learn. Practice. Feel prepared.
JavaScript Objective Questions and Answers - Set 2
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 2 of the series.
Practice JavaScript MCQs with Detailed Explanations
Answer at least 12 questions to submit and verify answers.
16 Which queue executes first in the event loop? High
Correct answer:
Microtask queue
Microtasks such as Promise callbacks execute before macrotasks.
17 What is the output? Promise.resolve(1) .then(x => x + 1) .then(x => { throw x; }) .catch(err => console.log(err)); High
Correct answer:
2
The value becomes 2 and is thrown, then caught and logged.
18 Which statement about prototypes is correct? Medium
Correct answer:
Prototypes enable inheritance
Prototypes enable objects to inherit properties and methods.
19 What does this keyword refer to inside an arrow function? Medium
Correct answer:
Lexical this from enclosing scope
Arrow functions inherit this from their lexical scope.
20 What is the output? console.log(typeof (() => {})); Medium
Correct answer:
function
Arrow functions are still of type function.
21 What will be the output order? console.log('A'); setTimeout(() => console.log('B')); Promise.resolve().then(() => console.log('C')); console.log('D'); High
Correct answer:
A D C B
Synchronous code runs first, then microtasks, then macrotasks.
22 What is the output? async function test() { return 5; } console.log(test()); Medium
Correct answer:
Promise {5}
Async functions always return a Promise.
23 What does await do internally? High
Correct answer:
Pauses execution of the async function
await pauses execution of the async function until the Promise resolves.
24 Which causes a memory leak in JavaScript? High
Correct answer:
Global variables
Global variables persist for the lifetime of the application and can cause memory leaks.
25 What is the output? let a = { x: 1 }; let b = a; a = null; console.log(b.x); Medium
Correct answer:
1
b still references the original object.
26 Which comparison avoids type coercion? Medium
Correct answer:
===
Strict equality checks both value and type.
27 What will be logged? console.log(1 + '2' + 3); Medium
Correct answer:
123
Number is coerced to string and concatenation occurs.
28 What is the output? console.log(true + false); Medium
Correct answer:
1
true becomes 1 and false becomes 0.
29 Which object is responsible for garbage collection? High
Correct answer:
JavaScript engine
The JavaScript engine handles garbage collection.
30 What happens if a Promise is neither resolved nor rejected? Medium
Correct answer:
It remains pending
The Promise stays in pending state indefinitely.