What will be the output of the following JavaScript code? [code] function person() { this.name = 'rahul'; } function obj()

Pham Quỳnh

New member
What will be the output of the following JavaScript code?
Code:
function person()
{  
        this.name = 'rahul';  
}  
function obj() 
{  
       obj.call(this)  
}  
obj.prototype = Object.create(person.prototype);  
const app = new obj();  
console.log(app.name);
A. undefined
B. runtime error
C. compilation error
D. rahul
 
Answer: d
Explanation: Object.create() method is used to create a new object with the specified properties. This is another way of creating a new object using specified object type. The particular function accepts two values as an argument.
 

Tìm kiếm

Back
Top