Refer to the following object:
const dog = {
firstName: 'Beau',
lastName: 'Boo',
get fullName() {
return this.firstName + ' ' + this.lastName;
}
};
How can a developer access the fullName property for dog?
The correct answer is A.
This object uses a getter:
get fullName() {
return this.firstName + ' ' + this.lastName;
}
A getter looks like a method when it is defined, but it is accessed like a normal property.
So the correct access syntax is:
dog.fullName
That returns:
'Beau Boo'
The important distinction is:
dog.fullName
not:
dog.fullName()
Because fullName is a getter property, not a regular function property.
Option B is incorrect because calling dog.fullName() tries to call the returned string as a function. Since 'Beau Boo' is not a function, that would cause a TypeError.
Option C is incorrect because there is no get object inside dog.
Option D is incorrect because there is no function object inside dog, and getters are not accessed that way.
Therefore, the verified answer is A.
Mila
4 days agoGracia
9 days agoLemuel
14 days agoSalley
19 days agoLashandra
24 days ago