Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

Salesforce JS-Dev-101 Exam - Topic 5 Question 10 Discussion

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?
A) dog.fullName
B) dog.fullName()
C) dog.get.fullName
D) dog.function.fullName()

Salesforce JS-Dev-101 Exam - Topic 5 Question 10 Discussion

Actual exam question for Salesforce's JS-Dev-101 exam
Question #: 10
Topic #: 5
[All JS-Dev-101 Questions]

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?

Show Suggested Answer Hide Answer
Suggested Answer: A

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.


Contribute your Thoughts:

0/2000 characters
Mila
4 days ago
A) dog.fullName is correct!
upvoted 0 times
...
Gracia
9 days ago
I’m leaning towards A too, but I keep second-guessing myself about whether I should use parentheses or not.
upvoted 0 times
...
Lemuel
14 days ago
I feel like it could be tricky; I want to say A, but what if there's something I'm missing about getters?
upvoted 0 times
...
Salley
19 days ago
I remember practicing a question like this where we accessed a property directly. A seems right to me.
upvoted 0 times
...
Lashandra
24 days ago
I think the answer might be A, but I'm not completely sure if I need to call it like a function.
upvoted 0 times
...

Save Cancel