Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

artdesiatnik
2,329 Pointswhy "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?
2 Answers

Steven Parker
215,356 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.

miikis
44,941 PointsHi Art,
That's just the design choice that the JavaScript creators made. It makes sense, if you think about it. Functions are these mechanisms that take some optional input, perform some action(s) and optionally return some output. If you only really need the "perform some action(s)" and "return some output" part of this mechanism — if you don't need inputs — then it it would be reasonable to just make this mechanism a read-only property.
But, really, this type of thing is just how JavaScript was designed to be. Sometimes it's arbitrary, other times it's just following idioms that existed in previous languages, like C.
miikis
44,941 Pointsmiikis
44,941 PointsGood point.
Aakash Srivastav
Full Stack JavaScript Techdegree Student 11,624 PointsAakash Srivastav
Full Stack JavaScript Techdegree Student 11,624 PointsThanks Steven :)