1. What is the main feature of prototypal inheritance in JavaScript?
A) It allows static inheritance
B) It allows objects to inherit from other objects
C) It prevents property access
D) It requires classes for inheritance
Show Explanation
2. What does the Object.create() method do in JavaScript?
A) It creates a new object with a specified prototype
B) It assigns properties to an existing object
C) It defines a new constructor function
D) It merges two objects
Show Explanation
3. What is the purpose of the Object.assign() method?
A) It creates a new object
B) It merges properties into an existing object
C) It defines a new object with prototype properties
D) It removes properties from an object
Show Explanation
4. How do JavaScript objects inherit properties from other objects?
A) Through static methods
B) Through constructors only
C) Through the prototype chain
D) Through class definitions
Show Explanation
5. What is the purpose of the prototype property in JavaScript?
A) To add properties and methods to a constructor function
B) To create new objects
C) To define static methods
D) To remove properties from an object
Show Explanation
6. How does prototypal inheritance differ from classical inheritance?
A) It requires classes
B) It uses constructor functions only
C) It allows objects to inherit directly from other objects
D) It prevents property sharing
Show Explanation
7. What does the constructor property of an object reference?
A) The object's parent
B) The object's own properties
C) The object's prototype
D) The function that created its prototype
Show Explanation
8. If you create an object using Object.create(proto), what does it inherit?
A) All properties from the global object
B) Properties from the specified prototype object
C) Only its own properties
D) Properties from a parent constructor
Show Explanation
9. What is the result of using Object.assign() on two objects?
A) It merges properties from source objects into the target object
B) It creates a deep copy of the source objects
C) It removes properties from the target object
D) It creates a new object without modifying the original
Show Explanation
10. How can you access the prototype of an object in JavaScript?
A) By using __proto__ property
B) By using Object.keys()
C) By using Object.getPrototypeOf()
D) By using prototype method
Show Explanation
11. What does the __proto__ property represent in JavaScript?
A) It defines static properties
B) It accesses the prototype of an object
C) It creates a new object
D) It initializes an object
Show Explanation
12. What happens to properties when an object is created with Object.create()?
A) The object inherits properties from the prototype
B) The object has its own properties by default
C) The object only has prototype properties
D) The object is created without any properties
Show Explanation
13. How can you set an object's prototype in JavaScript?
A) By using the constructor function
B) By using the Object.assign() method
C) By using Object.setPrototypeOf()
D) By defining properties
Show Explanation
14. What can be added to a prototype in JavaScript?
A) Only methods
B) Properties and methods
C) Only properties
D) Only static properties
Show Explanation
15. What is a key advantage of prototypal inheritance?
A) It prevents code duplication
B) It allows sharing properties and methods
C) It requires classes for all objects
D) It enforces strict typing
Show Explanation
16. Can functions be added to the prototype of an object in JavaScript?
A) Yes, they can be added as methods
B) No, only primitive types can be added
C) Only properties can be added
D) Functions cannot be shared
Show Explanation
17. What does the 'instanceof' operator do in JavaScript?
A) It checks if two objects are equal
B) It checks if an object is an instance of a specific class or prototype
C) It returns the prototype of an object
D) It creates a new instance
Show Explanation
18. How can an object created from a constructor function inherit properties?
A) By using Object.create()
B) By using Object.assign()
C) By calling the parent constructor function
D) By defining properties manually
Show Explanation
19. What happens if a property is not found in an object during property access?
A) An error is thrown
B) JavaScript searches the prototype chain for the property
C) The property is automatically created
D) The search stops at the object itself
Show Explanation
20. How does Object.create() facilitate inheritance in JavaScript?
A) It creates a shallow copy of an object
B) It directly modifies the prototype
C) It creates a new object with the specified prototype
D) It prevents property inheritance
Show Explanation