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
Tabetha
13 days ago
Yeah, A) makes sense. The syntax is clean and simple.
upvoted 0 times
...
Diane
18 days ago
Agreed! A) dog.fullName is the right choice. It's a getter.
upvoted 0 times
...
Alba
23 days ago
I think it's A) dog.fullName. Looks straightforward.
upvoted 0 times
...
Lawana
29 days ago
I thought it would be more complicated than that.
upvoted 0 times
...
Margart
1 month ago
B) dog.fullName() doesn't work, it's a getter!
upvoted 0 times
...
Reiko
1 month ago
Wait, is it really that simple?
upvoted 0 times
...
Filiberto
1 month ago
Totally agree, that's the way to do it!
upvoted 0 times
...
Mila
2 months ago
A) dog.fullName is correct!
upvoted 0 times
...
Gracia
2 months 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
2 months 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
2 months ago
I remember practicing a question like this where we accessed a property directly. A seems right to me.
upvoted 0 times
...
Lashandra
2 months 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