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!
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
why "length" is a property and not a method like pop or shift?
pop and shift are functions so is length, it does something and there is a code that counts and then returns the value, so why is it property?
Steven Parker228,077 Points
In general, methods represent actions and properties represent data.
While you're no doubt correct that there is some computation going on behind the scenes, what's probably most significant about length is that it does not affect the state of the object it is applied to. On the other hand, both pop and shift make lasting changes to the object.
So, in keeping with that general principle, it makes sense that length would be implemented as a computed property and not a method.