The verified answer is A .
This constructor function runs when new Person() is called:
function Person() {
this.firstName = " John " ;
}
So this line:
const myFather = new Person();
creates an object like this:
{
firstName: " John "
}
Then the prototype is assigned a method named job:
Person.prototype = {
job: x = > " Developer "
};
Because myFather is created from Person, it can access properties and methods from Person.prototype.
So:
myFather.firstName
returns:
" John "
And:
myFather.job()
returns:
" Developer "
Therefore:
const result = myFather.firstName + " " + myFather.job();
becomes:
const result = " John " + " " + " Developer " ;
Final value:
" John Developer "
Option B is incorrect because job() returns " Developer " , not undefined.
Option C is incorrect because job exists on Person.prototype, so it is callable.
Option D is incorrect because firstName is assigned inside the constructor.
Therefore, the verified answer is A .
Submit