JavaScript interviews often include tricky output-based questions that test your understanding of scoping, hoisting, closures, this, and more. Below is a detailed blog-style guide that walks through 25 frequently asked JS MCQ problems with their answers and clear explanations.
π₯ 1. Hoisting & TDZ
function sayHi() {
console.log(name);
console.log(age);
var name = 'Lydia';
let age = 21;
}
sayHi();
Answer: D β undefined and ReferenceError
Why:
β’ var name is hoisted and defaults to undefined until assignment.
β’ let age is hoisted but not initialized β so accessing it before declaration throws a ReferenceError.
This is due to the Temporal Dead Zone (TDZ) for let/const. ([Medium][1])
π₯ 2. Loop + setTimeout
for (var i = 0; i < 3; i++) {
setTimeout(() => console.log(i), 1);
}
for (let i = 0; i < 3; i++) {
setTimeout(() => console.log(i), 1);
}
Answer: C β 3 3 3 and 0 1 2
Why:
β’ var is function scoped β by the time callbacks run, i is 3.
β’ let is block scoped β each iteration captures its own i. ([Medium][1])
π₯ 3. this in regular vs arrow
const shape = {
radius: 10,
diameter() {
return this.radius * 2;
},
perimeter: () => 2 * Math.PI * this.radius,
};
console.log(shape.diameter());
console.log(shape.perimeter());
Answer: B β 20 and NaN
Why:
β’ Regular methods use object this.
β’ Arrow functions donβt get a this β they inherit from outer scope β this.radius is undefined β result is NaN. ([Medium][2])
π₯ 4. Unary plus + logical NOT
+true;
!'Lydia';
Answer: A β 1 and false
Why:
β’ +true converts to number β 1.
β’ 'Lydia' is truthy β ! makes it false. ([Medium][2])
π₯ 5. Property access with objects
const bird = { size: 'small' };
const mouse = { name: 'Mickey', small: true };
Answer: D β All of them are valid
Why:
β’ mouse.bird.size β actually invalid because bird isnβt a property of mouse.
However β bracket lookups like mouse[bird.size] or mouse[bird["size"]] resolve to mouse['small']. ([Medium][1])
π₯ 6. Objects reference
let c = { greeting: 'Hey!' };
let d;
d = c;
c.greeting = 'Hello';
console.log(d.greeting);
Answer: A β Hello
Why:
Objects are reference types β d points to same object as c. ([Medium][2])
π₯ 7. == vs === with primitives & objects
let a = 3;
let b = new Number(3);
let c = 3;
console.log(a == b);
console.log(a === b);
console.log(b === c);
Answer: C β true false false
Why:
β’ Loose == compares value β true.
β’ Strict === checks type β false for Number object. ([Medium][2])
π₯ 8. Static method on class instance
class Chameleon {
static colorChange(newColor) {
this.newColor = newColor;
return this.newColor;
}
constructor({ newColor = 'green' } = {}) {
this.newColor = newColor;
}
}
const freddie = new Chameleon({ newColor: 'purple' });
console.log(freddie.colorChange('orange'));
Answer: D β TypeError
Why:
Static methods are not accessible on instance. ([Medium][1])
π₯ 9. Typos & undefined variables
let greeting;
greetign = {}; // Typo!
console.log(greetign);
Answer: A β {}
Why:
In non-strict mode, this creates a global variable. ([Medium][1])
π₯ 10. Functions are objects
function bark() {
console.log('Woof!');
}
bark.animal = 'dog';
Answer: A β Nothing, this is fine!
Why:
Functions are first-class objects β can have properties. ([Medium][1])
π₯ 11. Adding methods after instances
function Person(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
const member = new Person('Lydia', 'Hallie');
Person.getFullName = function() {
return `${this.firstName} ${this.lastName}`;
};
console.log(member.getFullName());
Answer: A β TypeError
Why:
Method is added to constructor, not prototype. ([Medium][1])
π₯ 12. Forgetting new
const lydia = new Person('Lydia', 'Hallie');
const sarah = Person('Sarah', 'Smith');
console.log(lydia);
console.log(sarah);
Answer: A β Person { β¦ } and undefined
Why:
Calling constructor without new returns undefined. ([Medium][1])
π₯ 13. Event propagation phases
Answer: D β Capturing > Target > Bubbling
Why:
Standard DOM event propagation order. ([Placement Preparation][3])
π₯ 14. Prototypes exist for all objects
Answer: A β true
Every object in JS has a prototype chain (except the root). ([Placement Preparation][3])
π₯ 15. Number + string
sum(1, '2');
Answer: C β "12"
Why:
String concatenation takes precedence. ([Placement Preparation][3])
π₯ 16. Increment operator
let number = 0;
console.log(number++);
console.log(++number);
console.log(number);
Answer: C β 0 2 2
Why:
Postfix vs prefix increment gives different values. ([Placement Preparation][3])
π₯ 17. Tagged template literals
getPersonInfo`${person} is ${age} years old`;
Answer: B β array of strings, substitutions
Why:
Tagged templates pass strings array first, then values. ([Placement Preparation][3])
π₯ 18. Object literal comparison
Answer: C β βHmm.. You don't have an age I guessβ
Object comparisons always check references, not values. ([Placement Preparation][3])
π₯ 19. Rest parameters type
typeof args
Answer: C β "object"
Rest produces an array, and typeof [] is "object". ([Placement Preparation][3])
π₯ 20. Strict mode undeclared variable
function getAge() {
'use strict';
age = 21;
}
getAge();
Answer: C β ReferenceError
Strict mode forbids undeclared variables. ([Placement Preparation][3])
π₯ 21. eval()
const sum = eval('10*10+5');
Answer: A β 105
eval evaluates arbitrary JS expressions. ([Placement Preparation][3])
π₯ 22. sessionStorage lifespan
Answer: B β When the user closes the tab
Session storage is tab-specific. ([Placement Preparation][3])
π₯ 23. var redeclaration
var num = 8;
var num = 10;
console.log(num);
Answer: B β 10
var allows redeclaration. ([Placement Preparation][3])
π₯ 24. Objects vs Sets
set.has('1');
set.has(1);
Answer: C β true true false true
Object keys are strings; Set distinguishes types. ([Placement Preparation][3])
π₯ 25. Duplicate keys in object
const obj = { a: 'one', b: 'two', a: 'three' };
Answer: C β { a: "three", b: "two" }
Duplicate keys overwrite earlier ones. ([Placement Preparation][3])
Top comments (0)