Object-Oriented JavaScript (OOP) simplifies complex coding through its modular approach. Learn concepts like constructor functions, class syntax, prototypes, and inheritance with these 30 expertly curated multiple-choice questions (MCQs).
Constructor Functions (7 Questions)
Which keyword is used to define a constructor function in JavaScript? a) constructor b) function c) class d) init
What is the purpose of this in a constructor function? a) Refers to the global object b) Refers to the object being created c) Refers to a static method d) Refers to the parent class
What happens if you call a constructor function without the new keyword? a) It throws an error b) The global object gets modified c) The object is created but this is undefined d) No action is performed
In JavaScript, a constructor function typically starts with: a) a lowercase letter b) an uppercase letter c) a special character d) a number
How can you verify an object is an instance of a constructor function? a) Using object.prototype.constructor b) Using object.constructor c) Using instanceof d) Using typeof
What is returned implicitly by a constructor function if no return statement is provided? a) undefined b) The created object c) A string “constructor” d) Null
Which of the following is NOT true about constructor functions? a) They can create multiple objects b) They always require the this keyword c) They replace the prototype d) They are reusable
Class Syntax and Class Inheritance (7 Questions)
How do you define a class in JavaScript? a) class MyClass b) function class c) class = MyClass d) class.myClass
Which method is used for creating and initializing an object in a class? a) init() b) constructor() c) create() d) initialize()
How can a class inherit from another class in JavaScript? a) Using the extends keyword b) Using the inherit keyword c) Using the instanceof keyword d) Using the super keyword
What does the super keyword do in a derived class? a) Calls the parent class’s constructor b) Creates a new object c) Binds the method to the child class d) Invokes a static method
Can a class in JavaScript have multiple constructors? a) Yes, using overloading b) No, only one is allowed c) Yes, if static d) No, they are optional
Which statement is true about methods in a class? a) They can be static or instance-specific b) They must be declared outside the class body c) They cannot access this d) They cannot be asynchronous
How do you access a static method in JavaScript? a) Using an instance of the class b) Using the class name directly c) Using the super keyword d) Using this.methodName
Prototype and Prototype Chain (8 Questions)
What is the purpose of the prototype property in JavaScript? a) To store instance-specific data b) To share methods among instances c) To override the global object d) To ensure encapsulation
What is the default value of the prototype property in a constructor function? a) null b) An empty object c) Undefined d) A string
What does the prototype chain represent? a) A sequence of parent classes b) A hierarchical structure for objects c) The inheritance of methods and properties d) A data storage method
Which method is used to get the prototype of an object? a) Object.getPrototype() b) Object.getPrototypeOf() c) Object.prototype.get() d) Object.prototypeOf()
What happens if a property is not found in an object? a) The script throws an error b) It checks the global object c) It searches up the prototype chain d) The method halts
How can you add a method to an existing prototype? a) prototype.methodName b) object.prototype.methodName c) constructor.methodName d) object.addMethod()
What is Object.prototype? a) The default prototype for objects b) A method for prototype linking c) A deprecated feature in ES6 d) A static property
Which method breaks the prototype chain? a) Object.create(null) b) Object.freeze() c) Object.definePrototype() d) Object.setPrototype()
What does encapsulation in JavaScript achieve? a) Hiding implementation details b) Creating static methods c) Extending the prototype chain d) Ensuring inheritance
How can you make a property private in JavaScript? a) Use a # before the property name b) Use private keyword c) Use let d) Use static
Inheritance allows: a) Methods to be overwritten b) Multiple constructors c) Prototype deletion d) Changing the data type of this
What is polymorphism? a) Hiding data b) The ability of methods to take many forms c) A method to delete objects d) Linking multiple prototypes
What keyword is used to override a method in a subclass? a) override b) super c) extends d) None; just redeclare the method
What is the main benefit of polymorphism in OOP? a) Code reusability b) Data encapsulation c) Prototype chaining d) Dynamic typing
Encapsulation prevents: a) Direct modification of private variables b) The use of inheritance c) Creating objects d) Dynamic method binding
How do you access a private property in modern JavaScript? a) Using a method inside the class b) Directly using this.propertyName c) Using Object.getProperty() d) Using Object.prototype.property