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.
Tabetha
13 days agoDiane
18 days agoAlba
23 days agoLawana
29 days agoMargart
1 month agoReiko
1 month agoFiliberto
1 month agoMila
2 months agoGracia
2 months agoLemuel
2 months agoSalley
2 months agoLashandra
2 months ago