JavaScript OOP MCQs for Developer Interviews & Certification

1 min read

Object-Oriented Programming (OOP) in JavaScript allows developers to structure applications into modular, reusable objects that pair state (properties) with behavior (methods). Unlike class-based OOP languages like Java or C++, JavaScript natively uses prototypal inheritance, where objects inherit properties and methods directly from other objects via prototype chains (__proto__ and prototype). ES6 introduced class syntax (class, constructor, extends, super) as syntactical sugar over this underlying prototype model, alongside modern enhancements like private class fields (#field), static methods, and accessor properties (get/set). Understanding object instantiation, prototypal delegation, method overriding, and dynamic this resolution is essential for building scalable web architectures and excelling in technical software engineering assessments.

1. What is the primary difference between `__proto__` and `prototype` in JavaScript?

a) `__proto__` is an internal property on all objects pointing to their prototype, while `prototype` is a property on constructor functions used to build instances.
b) `prototype` is used by instances, while `__proto__` is used exclusively by classes.
c) They are identical aliases for the exact same object property.
d) `__proto__` is deprecated and has no relation to prototype inheritance.
Correct Answer: a) `__proto__` is an internal property on all objects pointing to their prototype, while `prototype` is a property on constructor functions used to build instances.
Explanation:
`__proto__` exists on every object to link to its prototype for delegation, whereas `prototype` is a property found on constructor functions and classes used to establish the prototype chain for created instances.

2. What happens during the execution of a constructor function when called with the `new` keyword?

a) A new empty object is created, its prototype is linked to the constructor's prototype, 'this' is bound to the new object, and the object is returned implicitly.
b) The constructor runs in the global scope and returns undefined.
c) A static class instance is compiled and stored in memory.
d) The parent class constructor is invoked automatically without arguments.
Correct Answer: a) A new empty object is created, its prototype is linked to the constructor's prototype, 'this' is bound to the new object, and the object is returned implicitly.
Explanation:
The `new` operator automates four key steps: object creation, prototype linking, `this` binding, and implicit return (unless an explicit object is returned).

3. What is the output of `console.log(typeof Person)` for an ES6 class `class Person {}`?

a) "function"
b) "object"
c) "class"
d) "undefined"
Correct Answer: a) "function"
Explanation:
In JavaScript, ES6 classes are syntactical sugar over prototype-based constructor functions, so typeof a class returns "function".

4. Are ES6 class declarations hoisted like function declarations?

a) Yes, they are hoisted to the top of their scope and can be called before definition.
b) No, they are hoisted like let/const into the Temporal Dead Zone and cannot be accessed before declaration.
c) Yes, but they initialize with a default value of undefined.
d) No, they are never hoisted under any circumstances.
Correct Answer: b) No, they are hoisted like let/const into the Temporal Dead Zone and cannot be accessed before declaration.
Explanation:
Class declarations are hoisted to their scope block, but they remain uninitialized in the Temporal Dead Zone until execution reaches the declaration line.

5. What will be printed to the console? class Animal { speak() { return "Noise"; } } class Dog extends Animal { speak() { return "Bark"; } } const d = new Dog(); console.log(d.speak());

a) "Bark"
b) "Noise"
c) TypeError
d) undefined
Correct Answer: a) "Bark"
Explanation:
Method overriding allows the child class `Dog` to provide a specialized implementation of `speak()`, shadowing the parent `Animal` method.

6. Which keyword allows accessing methods or properties of a parent class from within a child class?

a) parent
b) super
c) base
d) this
Correct Answer: b) super
Explanation:
The `super` keyword is used in derived classes to call parent constructors (`super()`) or reference parent prototype methods (`super.method()`).

7. What is the output of the following code snippet? class Counter { #count = 0; increment() { this.#count++; return this.#count; } } const c = new Counter(); console.log(c.increment());

a) 1
b) 0
c) TypeError
d) undefined
Correct Answer: a) 1
Explanation:
Private fields prefixed with `#` can be accessed and modified within class body methods. Incrementing `#count` from 0 yields 1.

8. What happens if you attempt to access a private field `#count` from outside the class body `console.log(c.#count);`?

a) It returns undefined.
b) It throws a SyntaxError during parsing.
c) It returns 0.
d) It returns null.
Correct Answer: b) It throws a SyntaxError during parsing.
Explanation:
Attempting to access private fields from outside their defining class declaration raises an immediate SyntaxError.

9. How do you define a static method in an ES6 class?

a) static myMethod() {}
b) function static myMethod() {}
c) const myMethod() {}
d) global myMethod() {}
Correct Answer: a) static myMethod() {}
Explanation:
The `static` keyword defines static methods or fields that belong to the class constructor itself rather than instances.

10. Can static methods access instance properties via `this`?

a) Yes, 'this' refers to the newly created instance.
b) No, 'this' inside a static method refers to the class constructor function itself, not any instance.
c) Yes, but only if the instance is passed as the first argument.
d) Static methods cannot use the 'this' keyword at all.
Correct Answer: b) No, 'this' inside a static method refers to the class constructor function itself, not any instance.
Explanation:
Inside static methods, `this` points to the class constructor, so instance-specific properties cannot be accessed directly.

11. What is the result of evaluating `d instanceof Animal` when `class Dog extends Animal {}` and `const d = new Dog();`?

a) true
b) false
c) TypeError
d) undefined
Correct Answer: a) true
Explanation:
The `instanceof` operator checks if `Animal.prototype` appears anywhere along the prototype chain of instance `d`.

12. How can you customize the behavior of the `instanceof` operator for a custom class?

a) By overriding `Symbol.hasInstance` static method
b) By overriding `toString`
c) By setting `constructor` property
d) It cannot be customized
Correct Answer: a) By overriding `Symbol.hasInstance` static method
Explanation:
Classes can define a static `[Symbol.hasInstance](instance)` method to customize custom `instanceof` evaluation logic.

13. What is the purpose of the `constructor` property on a prototype object?

a) It points back to the constructor function that created the instance.
b) It executes automatically when an object is deleted.
c) It stores private fields.
d) It defines parent class inheritance.
Correct Answer: a) It points back to the constructor function that created the instance.
Explanation:
Every prototype object has a `constructor` property pointing by default to the constructor function that owns the prototype.

14. What happens to the `constructor` property when you overwrite a prototype object entirely `Dog.prototype = { bark() {} };`?

a) It remains intact pointing to Dog.
b) It is lost (or points to Object), so it must be manually re-assigned if needed.
c) It throws a SyntaxError.
d) It automatically points to Animal.
Correct Answer: b) It is lost (or points to Object), so it must be manually re-assigned if needed.
Explanation:
Replacing `prototype` with a new object literal wipes out the default `constructor` link, requiring explicit `constructor: Dog` re-assignment.

15. Which of the following is a key benefit of using factory functions over classes in JavaScript?

a) They naturally encapsulate private state without requiring special syntax like `#` fields.
b) They execute faster at runtime than class instances.
c) They support multiple inheritance automatically.
d) They eliminate prototype chains entirely.
Correct Answer: a) They naturally encapsulate private state without requiring special syntax like `#` fields.
Explanation:
Factory functions leverage closures to maintain completely private variables and methods without syntax tokens like `#`.

16. What is prototypal inheritance delegation?

a) When an object delegates property lookups up its prototype chain if a property is not found locally.
b) Copying all properties from parent to child upon instantiation.
c) Compiling classes into static interfaces.
d) Sharing variables across global scope.
Correct Answer: a) When an object delegates property lookups up its prototype chain if a property is not found locally.
Explanation:
JavaScript uses delegation: if an object lacks a property, the engine looks up the chain to its prototype (`__proto__`).

17. What is the output of `Object.getPrototypeOf(d)` for `const d = new Dog()`?

a) Dog.prototype
b) Animal.prototype
c) Object.prototype
d) null
Correct Answer: a) Dog.prototype
Explanation:
`Object.getPrototypeOf(d)` returns the immediate prototype of instance `d`, which is `Dog.prototype`.

18. What is the output of `Object.getPrototypeOf(Dog.prototype)` when `class Dog extends Animal {}`?

a) Animal.prototype
b) Object.prototype
c) null
d) Animal
Correct Answer: a) Animal.prototype
Explanation:
In an ES6 class inheritance hierarchy, child prototype delegates to parent prototype (`Dog.prototype.__proto__ === Animal.prototype`).

19. What will be printed to the console? class User { get name() { return "Alice"; } } const u = new User(); console.log(u.name);

a) "Alice"
b) [Function: name]
c) undefined
d) TypeError
Correct Answer: a) "Alice"
Explanation:
A getter method prefixed with `get` is accessed like a property (without parentheses), returning "Alice".

20. What happens if a getter method is defined without a corresponding setter, and you try to assign `u.name = "Bob"` in strict mode?

a) It silently fails.
b) A TypeError is thrown.
c) A new property is created.
d) It throws a SyntaxError.
Correct Answer: b) A TypeError is thrown.
Explanation:
In strict mode, attempting to assign to a getter-only property throws a TypeError.

21. Which pattern combines multiple independent objects or classes into a single class or object in JavaScript?

a) Mixins
b) Singletons
c) Factories
d) Proxies
Correct Answer: a) Mixins
Explanation:
Mixins provide behavior sharing by copying or delegating methods across independent objects since JavaScript lacks multiple class inheritance.

22. What is the Singleton pattern in JavaScript OOP?

a) A design pattern that restricts class instantiation to a single object instance.
b) A class with only one static method.
c) An object without a prototype.
d) A function that runs only once.
Correct Answer: a) A design pattern that restricts class instantiation to a single object instance.
Explanation:
The Singleton pattern ensures a class has only one instance and provides a global access point to it.

23. How can a Singleton be implemented in an ES6 class?

a) By storing an instance check inside a static property or constructor return override.
b) By using private fields only.
c) By extending Object.prototype.
d) It is built-in as a keyword.
Correct Answer: a) By storing an instance check inside a static property or constructor return override.
Explanation:
A constructor can check if an instance already exists in a static field; if so, it returns that existing instance.

24. What is the output of `Object.create(null)` regarding prototype methods?

a) It creates an object with no prototype, meaning it lacks methods like `toString` or `hasOwnProperty`.
b) It inherits from Object.prototype.
c) It throws a TypeError.
d) It creates an array.
Correct Answer: a) It creates an object with no prototype, meaning it lacks methods like `toString` or `hasOwnProperty`.
Explanation:
Passing `null` to `Object.create` produces a dictionary object completely detached from `Object.prototype`.

25. What is method chaining in JavaScript OOP?

a) Returning `this` from instance methods so multiple method calls can be chained together in a single statement.
b) Inheriting methods across multiple parent classes.
c) Calling asynchronous methods with await.
d) Chaining constructor calls with super.
Correct Answer: a) Returning `this` from instance methods so multiple method calls can be chained together in a single statement.
Explanation:
Method chaining relies on methods returning the current instance (`return this`), allowing syntax like `obj.setName('A').setAge(10).save()`.

26. What does the `Proxy` object allow in JavaScript OOP?

a) Defining custom behavior for fundamental object operations like property lookup, assignment, and function invocation.
b) Creating private classes.
c) Connecting to remote network servers.
d) Compiling code to WebAssembly.
Correct Answer: a) Defining custom behavior for fundamental object operations like property lookup, assignment, and function invocation.
Explanation:
A `Proxy` wraps an object and intercepts operations using traps (like `get`, `set`, `has`), enabling powerful metaprogramming.

27. What is a `Reflect` object in JavaScript?

a) A built-in object providing methods for interceptable JavaScript operations corresponding to Proxy traps.
b) A tool used to clone objects deeply.
c) A testing framework for classes.
d) A utility to inspect DOM elements.
Correct Answer: a) A built-in object providing methods for interceptable JavaScript operations corresponding to Proxy traps.
Explanation:
`Reflect` provides static methods that mirror runtime operations, often used inside Proxy traps to forward operations to the target object.

28. What happens if a derived class constructor fails to call `super()` before accessing `this`?

a) A ReferenceError is thrown.
b) A SyntaxError is thrown.
c) It defaults to global 'this'.
d) It executes normally.
Correct Answer: a) A ReferenceError is thrown.
Explanation:
In ES6 classes, `this` is uninitialized in a derived constructor until `super()` establishes the parent instance context.

29. Can an ES6 class extend a built-in constructor like `Array` or `Error`?

a) Yes, built-in constructors can be subclassed seamlessly.
b) No, built-in objects are sealed against inheritance.
c) Only for Error, not for Array.
d) Only in strict mode.
Correct Answer: a) Yes, built-in constructors can be subclassed seamlessly.
Explanation:
ES6 classes allow subclassing native built-ins like `Array`, `Error`, `Map`, and `Date` directly.

30. What is polymorphism in Object-Oriented Programming?

a) The ability of different classes to respond to the same method call with specialized behaviors.
b) The ability to change a class prototype at runtime.
c) Hiding internal data fields.
d) Creating multiple instances of a class.
Correct Answer: a) The ability of different classes to respond to the same method call with specialized behaviors.
Explanation:
Polymorphism allows objects of different types to share a common interface while implementing distinct internal logic (e.g., method overriding).

31. What is encapsulation in Object-Oriented Programming?

a) Bundling data and methods that operate on that data within a single unit while restricting external access.
b) Inheriting properties from multiple parents.
c) Overriding methods in child classes.
d) Converting objects to JSON strings.
Correct Answer: a) Bundling data and methods that operate on that data within a single unit while restricting external access.
Explanation:
Encapsulation protects object state by hiding internal details and exposing controlled public interfaces.

32. How are private methods declared in a JavaScript class (ES2022+)?

a) #methodName() {}
b) private methodName() {}
c) hidden methodName() {}
d) static private methodName() {}
Correct Answer: a) #methodName() {}
Explanation:
Like private fields, private methods are prefixed with `#` and can only be invoked within the class body.

33. Can private fields or methods be static in a JavaScript class?

a) Yes, static private fields and methods can be declared using `static #fieldName` or `static #methodName()`.
b) No, private members must always be instance-specific.
c) Only static fields can be private, not static methods.
d) Only in TypeScript.
Correct Answer: a) Yes, static private fields and methods can be declared using `static #fieldName` or `static #methodName()`.
Explanation:
ES2022 supports static private members accessed exclusively by static methods within the class.

34. What is the output of `Object.isExtensible(obj)` on an ordinary newly created object?

a) true
b) false
c) undefined
d) TypeError
Correct Answer: a) true
Explanation:
Normal objects are extensible by default, allowing new properties to be added.

35. What method permanently locks an object so that no new properties can be added, existing properties cannot be deleted, but existing property values can still be changed?

a) Object.seal()
b) Object.freeze()
c) Object.preventExtensions()
d) Object.lock()
Correct Answer: a) Object.seal()
Explanation:
`Object.seal()` seals an object, preventing new properties and deletions while allowing modification of existing writable values.

36. What is the difference between `Object.freeze()` and `Object.seal()`?

a) `Object.freeze()` makes existing properties read-only in addition to sealing structural changes.
b) `Object.freeze()` allows adding new properties.
c) `Object.seal()` prevents modifying existing values.
d) There is no difference.
Correct Answer: a) `Object.freeze()` makes existing properties read-only in addition to sealing structural changes.
Explanation:
Freezing prevents additions, deletions, *and* value changes, whereas sealing only prevents structural additions/deletions.

37. What is the output of `Object.isSealed(Object.freeze({}))`?

a) true
b) false
c) TypeError
d) undefined
Correct Answer: a) true
Explanation:
A frozen object is also inherently sealed because sealed objects forbid additions and deletions.

38. What is the output of `Object.isFrozen(Object.seal({}))`?

a) false
b) true
c) TypeError
d) undefined
Correct Answer: a) false
Explanation:
A sealed object is not necessarily frozen because its existing properties can still be modified unless explicitly made non-writable.

39. What will be printed to the console? class Parent { constructor() { this.name = "Parent"; this.printName(); } printName() { console.log(this.name); } } class Child extends Parent { constructor() { super(); this.name = "Child"; } printName() { console.log(this.name); } } new Child();

a) "Child"
b) "Parent"
c) undefined
d) TypeError
Correct Answer: a) "Child"
Explanation:
Due to polymorphic dynamic dispatch, when `super()` runs in `Parent`, `this.printName()` invokes `Child`'s overridden `printName`, logging "Child" even though parent constructor ran first.

40. How do you check if an object has an own property (ignoring prototype chain)?

a) Object.hasOwn(obj, prop)
b) obj.hasProperty(prop)
c) prop in obj
d) Object.contains(obj, prop)
Correct Answer: a) Object.hasOwn(obj, prop)
Explanation:
`Object.hasOwn()` is the modern ES2022 static replacement for `obj.hasOwnProperty(prop)`.

41. What is the output of `"toString" in {}`?

a) true
b) false
c) TypeError
d) undefined
Correct Answer: a) true
Explanation:
The `in` operator checks both own properties and properties inherited along the prototype chain (found on `Object.prototype`).

42. What is the output of `Object.hasOwn({}, "toString")`?

a) false
b) true
c) TypeError
d) undefined
Correct Answer: a) false
Explanation:
`Object.hasOwn` checks exclusively for own properties, returning false for inherited properties like `toString`.

43. What is the role of the `Symbol.toStringTag` symbol in JavaScript classes?

a) It customizes the string returned by `Object.prototype.toString.call(instance)`.
b) It converts instance to string automatically.
c) It defines private string fields.
d) It overrides template literal interpolation.
Correct Answer: a) It customizes the string returned by `Object.prototype.toString.call(instance)`.
Explanation:
Defining `get [Symbol.toStringTag]() { return 'MyClass'; }` changes the tag output in `[object MyClass]`.

44. What is the output of `class Foo { get [Symbol.toStringTag]() { return 'Bar'; } }` when running `Object.prototype.toString.call(new Foo())`?

a) "[object Bar]"
b) "[object Foo]"
c) "[object Object]"
d) "Bar"
Correct Answer: a) "[object Bar]"
Explanation:
`Symbol.toStringTag` customizes the default object type string representation.

45. Can arrow functions be used as methods inside ES6 classes if you want `this` to refer to the class instance?

a) Yes, arrow function class properties lexically bind `this` to the instance, but they exist on each instance rather than the prototype.
b) No, arrow functions throw a SyntaxError inside classes.
c) Yes, and they are stored on the class prototype.
d) No, they bind `this` to the global object.
Correct Answer: a) Yes, arrow function class properties lexically bind `this` to the instance, but they exist on each instance rather than the prototype.
Explanation:
Using arrow syntax for class properties binds `this` to the instance upon creation, preventing loss of context during callbacks, but wastes memory as they are not on the prototype.

46. What is the recommended approach for handling `this` context binding in standard ES6 class methods when passed as callbacks?

a) Explicitly binding them in the constructor using `this.method = this.method.bind(this);` or wrapping them in arrow functions.
b) Using `var self = this;`.
c) Declaring the method as static.
d) Using the `global` keyword.
Correct Answer: a> Explicitly binding them in the constructor using `this.method = this.method.bind(this);` or wrapping them in arrow functions.
Explanation:
Standard methods lose their `this` context when detached as callbacks; binding in the constructor preserves `this` while keeping the method on the prototype.

47. What is the output of `typeof class {}`?

a) "function"
b) "object"
c) "class"
d) "undefined"
Correct Answer: a) "function"
Explanation:
Anonymous class expressions evaluate to type "function".

48. Can classes be passed as arguments to functions (First-class citizens)?

a) Yes, classes are functions and can be passed as arguments, returned from functions, and assigned to variables.
b) No, classes must be statically declared.
c) Only if they are abstract.
d) Only inside async functions.
Correct Answer: a) Yes, classes are functions and can be passed as arguments, returned from functions, and assigned to variables.
Explanation:
Because classes are first-class citizens (functions under the hood), they can be passed around dynamically.

49. What is a mixin factory function pattern in JavaScript OOP?

a) A function that takes asuperclass and returns a new subclass augmented with additional methods.
b) A function that freezes objects.
c) A method to delete private properties.
d) A tool to convert classes to functions.
Correct Answer: a) A function that takes a superclass and returns a new subclass augmented with additional methods.
Explanation:
Mixin factories allow dynamic composition of inheritance hierarchies in JavaScript (e.g., `const Flyer = (superclass) => class extends superclass { fly() {} }`).

50. What is the output of `Object.getOwnPropertyNames(Array.prototype).length > 0`?

a) true
b) false
c) TypeError
d) undefined
Correct Answer: a) true
Explanation:
`Array.prototype` contains all built-in array methods (`map`, `filter`, `push`, etc.) as its own properties.

51. What is the purpose of `Object.assign(target, ...sources)` in OOP context?

a) To copy enumerable own properties from source objects to a target object (often used for object composition or mixins).
b) To establish prototype inheritance links.
c) To freeze objects.
d) To create private fields.
Correct Answer: a) To copy enumerable own properties from source objects to a target object (often used for object composition or mixins).
Explanation:
`Object.assign` shallow copies properties, making it useful for composing behaviors onto target instances or prototypes.

52. What happens if a class constructor explicitly returns a primitive value like `return 100;` when invoked with `new`?

a) The primitive return value is ignored, and the newly created instance is returned.
b) The number 100 is returned.
c) A TypeError is thrown.
d) undefined is returned.
Correct Answer: a) The primitive return value is ignored, and the newly created instance is returned.
Explanation:
Constructors ignoring primitive returns ensure the new instance object is always returned correctly.

53. What happens if a class constructor explicitly returns an object like `return { custom: true };` when invoked with `new`?

a) The returned object overrides the newly created instance completely.
b) The returned object is ignored.
c) A TypeError is thrown.
d) Both objects are merged.
Correct Answer: a) The returned object overrides the newly created instance completely.
Explanation:
If a constructor explicitly returns an object, that object becomes the return value of the `new` expression, overriding the instance.

54. Which of the following is true regarding constructor function inheritance prior to ES6 classes?

a) It required borrowing constructor via `Parent.call(this)` and manually wiring prototypes via `Child.prototype = Object.create(Parent.prototype)`.
b) It was impossible to achieve inheritance.
c) It required the `extends` keyword.
d) It used the `private` keyword.
Correct Answer: a) It required borrowing constructor via `Parent.call(this)` and manually wiring prototypes via `Child.prototype = Object.create(Parent.prototype)`.
Explanation:
Classical prototypal inheritance setup before ES6 classes required explicit constructor borrowing and prototype chain linking.

55. Why is setting `Child.prototype.constructor = Child` necessary after `Child.prototype = Object.create(Parent.prototype)`?

a) Because `Object.create` overwrites the prototype object, resetting its `constructor` property to `Parent`.
b) To enable private fields.
c) To prevent garbage collection.
d) It is not necessary.
Correct Answer: a) Because `Object.create` overwrites the prototype object, resetting its `constructor` property to `Parent`.
Explanation:
Re-assigning the prototype link points `constructor` to `Parent`, so restoring `Child.prototype.constructor = Child` maintains correct metadata.

56. What is the output of `typeof Object`?

a) "function"
b) "object"
c) "constructor"
d) "undefined"
Correct Answer: a) "function"
Explanation:
`Object` is a built-in constructor function, so `typeof Object` evaluates to "function".

57. What is the output of `typeof Object.prototype`?

a) "object"
b) "function"
c) "prototype"
d) "undefined"
Correct Answer: a) "object"
Explanation:
Prototypes are ordinary objects, so `typeof Object.prototype` evaluates to "object".

58. Can you call a superclass static method from a subclass static method using `super`?

a) Yes, static methods inherit from parent classes and `super` points to the parent class constructor.
b) No, static methods cannot use `super`.
c) Only if instantiated first.
d) Only in strict mode.
Correct Answer: a) Yes, static methods inherit from parent classes and `super` points to the parent class constructor.
Explanation:
Static inheritance allows subclasses to inherit static methods and call them via `super.staticMethod()`.

59. What is the output of `class A {} class B extends A {} console.log(Object.getPrototypeOf(B) === A);`?

a) true
b) false
c) TypeError
d) undefined
Correct Answer: a) true
Explanation:
In class inheritance, the child constructor inherits from the parent constructor (`B.__proto__ === A`), enabling static inheritance.

60. What is a major advantage of encapsulation in JavaScript OOP?

a) It hides internal implementation details and prevents unauthorized state mutation from outside code.
b) It makes code run twice as fast.
c) It automatically generates unit tests.
d) It eliminates memory leaks.
Correct Answer: a) It hides internal implementation details and prevents unauthorized state mutation from outside code.
Explanation:
Encapsulation ensures data integrity by controlling how internal object states are accessed and mutated.

61. What will happen if you attempt to define a class with a duplicate constructor method in the class body?

a) A SyntaxError is thrown during parsing.
b) The second constructor overrides the first silently.
c) A TypeError is thrown at runtime.
d) Both constructors execute.
Correct Answer: a) A SyntaxError is thrown during parsing.
Explanation:
Defining more than one `constructor` method in a single ES6 class body triggers an immediate SyntaxError.

62. Can an ES6 class have zero constructor definitions written explicitly?

a) Yes, a default constructor is generated automatically for parent and derived classes.
b) No, every class requires an explicit constructor.
c) Only if it has static methods.
d) Only if it extends another class.
Correct Answer: a) Yes, a default constructor is generated automatically for parent and derived classes.
Explanation:
If omitted, JavaScript generates a default constructor (empty for base classes, forwarding arguments and calling `super(...args)` for derived classes).

63. What is the purpose of `Object.preventExtensions(obj)`?

a) It prevents any new properties from being added to the object.
b) It freezes all property values.
c) It deletes all prototype links.
d) It makes properties non-enumerable.
Correct Answer: a) It prevents any new properties from being added to the object.
Explanation:
`Object.preventExtensions()` locks the object's extensibility so no new properties can be added.

64. What is the return value of `Object.isExtensible(Object.preventExtensions({}))`?

a) false
b) true
c) TypeError
d) undefined
Correct Answer: a) false
Explanation:
Once prevented from extension, `Object.isExtensible` returns false.

65. Which of the following describes object composition?

a) Building complex objects by combining simpler, independent objects or behaviors rather than deep class inheritance.
b) Inheriting from five parent classes simultaneously.
c) Overriding built-in array methods.
d) Using private fields.
Correct Answer: a) Building complex objects by combining simpler, independent objects or behaviors rather than deep class inheritance.
Explanation:
Object composition favors 'has-a' relationships over rigid 'is-a' class inheritance hierarchies.

66. What is the output of `typeof class Foo {}`?

a) "function"
b) "object"
c) "class"
d) "undefined"
Correct Answer: a) "function"
Explanation:
Classes in JavaScript are functions under the hood.

67. What is the prototype of a class constructor function itself (e.g., `class A {}`)?

a) Function.prototype
b) Object.prototype
c) null
d) A.prototype
Correct Answer: a) Function.prototype
Explanation:
Since classes are functions, their internal prototype (`__proto__`) points to `Function.prototype`.

68. What is the output of `Object.prototype.toString.call(null)`?

a) "[object Null]"
b) "[object Object]"
c) "[object Undefined]"
d) "null"
Correct Answer: a) "[object Null]"
Explanation:
`Object.prototype.toString.call(null)` returns `[object Null]`.

69. What is the output of `Object.prototype.toString.call(undefined)`?

a) "[object Undefined]"
b) "[object Null]"
c) "[object Object]"
d) "undefined"
Correct Answer: a) "[object Undefined]"
Explanation:
`Object.prototype.toString.call(undefined)` returns `[object Undefined]`.

70. Can you use `this` inside an ES6 class field initializer?

a) Yes, `this` refers to the newly created instance.
b) No, it throws a SyntaxError.
c) Only inside static field initializers.
d) Only if super() has been called.
Correct Answer: a) Yes, `this` refers to the newly created instance.
Explanation:
Instance field initializers can access `this` and refer to other methods or fields on the instance.

71. What happens when a static field initializer accesses `this`?

a) `this` refers to the class constructor function itself.
b) `this` refers to the global object.
c) It throws a ReferenceError.
d) It returns undefined.
Correct Answer: a) `this` refers to the class constructor function itself.
Explanation:
Inside static initializers or static methods, `this` points to the class constructor.

72. What is the primary purpose of getters and setters in JavaScript OOP?

a) To control and intercept access or modification of object properties, enabling validation or computed values.
b) To make properties private.
c) To replace methods entirely.
d) To speed up property lookups.
Correct Answer: a> To control and intercept access or modification of object properties, enabling validation or computed values.
Explanation:
Getters and setters provide a clean property-access interface while executing custom logic behind the scenes.

73. What is the result of `class X extends null {} const x = new X(); console.log(x instanceof Object);`?

a) false
b) true
c) TypeError
d) undefined
Correct Answer: a) false
Explanation:
Extending `null` creates a base class whose prototype does not inherit from `Object.prototype`, so `x instanceof Object` evaluates to false.

74. What is a null-prototype class (`class X extends null`)?

a) A class whose prototype object does not inherit from `Object.prototype`.
b) A class that cannot be instantiated.
c) A class with no methods.
d) A deprecated ES5 feature.
Correct Answer: a) A class whose prototype object does not inherit from `Object.prototype`.
Explanation:
Extending `null` removes `Object.prototype` from the prototype chain of class instances.

75. What will be printed by `const obj = { get a() { return 1; } }; console.log(delete obj.a);`?

a) true
b) false
c) TypeError
d) undefined
Correct Answer: a) true
Explanation:
Deleting an own property (even a getter) from an ordinary object returns true and removes the property.

76. What is the output of `Boolean(class {})`?

a) true
b) false
c) TypeError
d) undefined
Correct Answer: a) true
Explanation:
Classes are functions and all functions evaluate to truthy in boolean contexts.

77. Which design pattern is used to dynamically add responsibilities to an object without altering its class?

a) Decorator pattern
b) Singleton pattern
c) Factory pattern
d) Observer pattern
Correct Answer: a) Decorator pattern
Explanation:
The Decorator pattern dynamically attaches behavior or state to objects wrapping them.

78. What is the Observer pattern in JavaScript OOP?

a) A pattern where an object (subject) maintains a list of dependents (observers) and notifies them of state changes.
b) A tool to inspect DOM elements.
c) A way to freeze objects.
d) A method for garbage collection.
Correct Answer: a) A pattern where an object (subject) maintains a list of dependents (observers) and notifies them of state changes.
Explanation:
The Observer pattern enables publish-subscribe notification mechanisms between decoupled objects.

79. Can you define computed property names in ES6 class method definitions?

a) Yes, using square brackets `[Symbol.iterator]() {}` or `['meth' + 'ods']() {}`.
b) No, class method names must be static identifiers.
c) Only for static methods.
d) Only inside constructor.
Correct Answer: a) Yes, using square brackets `[Symbol.iterator]() {}` or `['meth' + 'ods']() {}`.
Explanation:
ES6 classes support computed property names for methods, getters, setters, and fields.

80. What is the output of `class A { static x = 1; } class B extends A {} console.log(B.x);`?

a) 1
b) undefined
c) TypeError
d) null
Correct Answer: a) 1
Explanation:
Subclasses inherit static properties and methods from their parent class constructor via prototype delegation on the constructor chain.

81. What is prototype pollution in JavaScript?

a) A vulnerability where an attacker manipulates `Object.prototype` to inject properties into all objects across an application.
b) Deleting Object.prototype.
c) Exceeding the call stack limit.
d) Creating too many class instances.
Correct Answer: a) A vulnerability where an attacker manipulates `Object.prototype` to inject properties into all objects across an application.
Explanation:
Prototype pollution occurs when insecure recursive merges or assignments allow modifying shared object prototypes.

82. How can you protect an application against prototype pollution?

a) By freezing `Object.prototype`, using null-prototype objects (`Object.create(null)`), or sanitizing input keys like `__proto__`.
b) By using arrow functions exclusively.
c) By avoiding classes.
d) By enabling strict mode.
Correct Answer: a) By freezing `Object.prototype`, using null-prototype objects (`Object.create(null)`), or sanitizing input keys like `__proto__`.
Explanation:
Safeguards against prototype pollution include locking prototypes and filtering special keys like `__proto__`, `constructor`, and `prototype`.

83. What is the return value of `Reflect.has({}, "toString")`?

a) true
b) false
c) TypeError
d) undefined
Correct Answer: a) true
Explanation:
`Reflect.has` mirrors the `in` operator, checking prototype inheritance and returning true for `toString`.

84. What is the output of `Reflect.ownKeys({ a: 1 })`?

a) ["a"]
b) ["a", "toString"]
c) []
d) TypeError
Correct Answer: a) ["a"]
Explanation:
`Reflect.ownKeys()` returns all own property keys (string keys and symbols), excluding inherited prototype properties.

85. What is the output of `class A { #x = 10; getX(obj) { return obj.#x; } } const a = new A(); console.log(a.getX(new A()));`?

a) 10
b) TypeError
c) undefined
d) SyntaxError
Correct Answer: a) 10
Explanation:
JavaScript private fields permit 'same-class' private access, allowing an instance of a class to access private fields of another instance of the same class.

86. What happens if you try to access a private field `#x` on an instance of a *different* class that also has `#x`?

a) A TypeError is thrown because private fields are strictly scoped to their defining class brand.
b) It returns the value successfully.
c) It returns undefined.
d) A SyntaxError is thrown.
Correct Answer: a) A TypeError is thrown because private fields are strictly scoped to their defining class brand.
Explanation:
Private fields enforce strict branding; accessing them from outside the defining class body or on foreign class instances throws a TypeError.

87. What is the output of `console.log(Array.prototype.__proto__ === Object.prototype)`?

a) true
b) false
c) TypeError
d) undefined
Correct Answer: a) true
Explanation:
`Array.prototype` inherits directly from `Object.prototype`.

88. What is the output of `console.log(Object.prototype.__proto__ === null)`?

a) true
b) false
c) TypeError
d) undefined
Correct Answer: a) true
Explanation:
`Object.prototype` is the root of the standard prototype chain, so its `__proto__` is `null`.

89. What is the output of `class A {} console.log(A.prototype.constructor === A);`?

a) true
b) false
c) TypeError
d) undefined
Correct Answer: a) true
Explanation:
Every class prototype links back to its class constructor via the `constructor` property.

90. Can class declarations be anonymous?

a) Yes, e.g., `const X = class { constructor() {} };`
b) No, class names are mandatory.
c) Only in strict mode.
d) Only when exported as default.
Correct Answer: a) Yes, e.g., `const X = class { constructor() {} };`
Explanation:
Classes can be declared anonymously and assigned to variables or passed as expressions.

91. What is the name property of an anonymous class expression `const X = class {}`?

a) "X" (inferred from variable assignment)
b) ""
c) "anonymous"
d) undefined
Correct Answer: a) "X" (inferred from variable assignment)
Explanation:
JavaScript engines infer class and function names from variable assignments when assigned anonymously.

92. What is the output of `class {}` name property when evaluated directly?

a) ""
b) "anonymous"
c) undefined
d) TypeError
Correct Answer: a) ""
Explanation:
Unassigned anonymous class expressions have an empty string `name` property.
← Previous: JavaScript Interview Questions MCQs
Next →: JavaScript Prototypes & Inheritance MCQs for Developer Interviews
Newpython variables & datatypes MCQs

Python Variables & Data Types MCQs

Variables in Python act as dynamic references reserved in memory to store objects, operating without explicit data type declarations due…

By MCQs Generator
NewLatest Python Operators MCQs

Latest Python Operators MCQs

Operators in Python are special symbols and keywords used to manipulate data, perform mathematical computations, make boolean comparisons, and control…

By MCQs Generator
NewJavaScript Arrays & Array Methods MCQs

JavaScript Arrays & Array Methods MCQs

JavaScript arrays are dynamic, high-level list-like data structures designed to store ordered collections of data types under a single variable.…

By MCQs Generator