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 Practice Getters and Setters in JavaScript Practicing Getters and Setters Creating a Setter Method Solution

Swan The Human
seal-mask
.a{fill-rule:evenodd;}techdegree
Swan The Human
Full Stack JavaScript Techdegree Student 19,338 Points

Should the getter for the setter be before the setter or after?

Just out of curiosity. In the tutorial it showed the writing of the setter first, and then the getter for that setter was added in and placed BEFORE the setter.

My question is, does it matter if the getter that returns the backing property of the setter is written before or after its corresponding setter?

1 Answer

It shouldn't matter when it comes to functionality, but it's good practice to put getter before setter for better readability.

Swan The Human
seal-mask
.a{fill-rule:evenodd;}techdegree
Swan The Human
Full Stack JavaScript Techdegree Student 19,338 Points

Thanks a lot! I figured as much but I wanted to know what was proper etiquette for future reference. Thanks again for the fast response!