- A undefined
- B runtime error
- C compilation error
- D rahul
- Share this MCQ
Answer:
D
Here, we create a prototype object with a
Share this MCQ
The Object.create()
method is used to create a new object with the specified properties. It is a way of creating a new object using an existing object as the prototype. The Object.create()
method accepts two arguments: the prototype object and an optional property descriptor object.
The prototype object is the object that the newly created object will inherit from. The property descriptor object is optional and can be used to specify the characteristics of the properties to be added to the new object.
For example:
const prototype = {
sayHello: function() {
console.log('Hello');
}
};
const object = Object.create(prototype);
object.sayHello(); // Output: "Hello"
Here, we create a prototype object with a
sayHello
method. We then use the Object.create()
method to create a new object that has the prototype object as its prototype. The new object inherits the sayHello method from the prototype object, so we can call it on the object.
Click me to Read more Question & Answer of
Javascript Classes MCQ
Share this MCQ