Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Object-Oriented JavaScript Getters and Setters Reviewing Getters and Setters

Ha Yeong Jeong
Ha Yeong Jeong
4,940 Points

The value returned from a getter method is stored: nowhere.

Does anyone know and can explain the reason for the quiz question below?

Q. The value returned from a getter method is stored: correct answer --> "nowhere"

From the returned results below, I see the value is stored inside the backing field of '_phone'.

Setter method called: [object Object]
Owner { name: 'Ashley', address: '123 Main St.', _phone: '1112223333' }
1112223333

If then, why do they say the value from the getter method is stored nowhere?

Thank you so much in advance!

2 Answers

Steven Parker
Steven Parker
231,269 Points

A getter method might return a value from a backing store, but it could also perform some process to create the return value. The actual return value isn't stored anywhere by the getter itself, but the code calling it might store it.

Ha Yeong Jeong
Ha Yeong Jeong
4,940 Points

If so, why is the "backing store" not the correct answer?

I mean, if a value assigned by the setter and called by the getter is stored nowhere, what is the purpose of setting any value using them? The value will go away and be stored nowhere. Sounds too volatile. I understand they are for dynamic inputs. But, still, I don't get their true purpose;;;;

Also, I think the object shown below conflicts with the answer. Because it is showing the backing field of _phone set with the value '1112223333' :

Setter method called: [object Object] Owner { name: 'Ashley', address: '123 Main St.', _phone: '1112223333' }

I am sorry, but it is so confusing to me. I really appreciate your kind answer!

Steven Parker
Steven Parker
231,269 Points

The question is generic and doesn't refer to that specific example, and some getter methods may not use a backing store at all. Consider this example:

    get fullname() { return `${this.firstname} ${this.lastname}`; }
Ha Yeong Jeong
Ha Yeong Jeong
4,940 Points

Thank you for the above example. I appreciate your help.