Single Choice
Easy
QWhat would the following JavaScript code produce?
function person()
{
this.name = 'rahul';
}
function obj()
{
obj.call(this)
}
obj.prototype = Object.create(person.prototype);
const app = new obj();
console.log(app.name);
ID: #4999
Javascript Classes MCQ
219 views
Question Info
#4999Q ID
EasyDifficulty
Javascript Classes MCQTopic
Your Answer
Choose the Best Option
Click any option to instantly check if you're correct.
Correct Answer
Explanation
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. Continue Practice
Share
Share This Question
Challenge a friend or share with your study group.
More from This Topic