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.

Java Java Objects (Retired) Meet Objects Welcome Back

Nick Vitsinsky
Nick Vitsinsky
7,246 Points

What does () represents in toLowerCase();

What does () represents in someWords.toLowerCase(); and why we cannot simply call a method to variable like someWords.to toLowerCase?

5 Answers

Carlos Federico Puebla Larregle
Carlos Federico Puebla Larregle
21,073 Points

That's right. For example in Java if you want to know the "length" of a String you would use the method "length"

string.length();

But if you want to know the length of an Array, you have to use the property length, use you would do it like this:

Array.length;

I hope that helps a little bit.

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

It just represents that you're calling the method toLowerCase on that string. String is an object in JavaScript and has many methods associated with it. Some methods take arguments... this one does not. You can view the MDN documentation on toLowerCase here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLowerCase

Daniel Maia
Daniel Maia
6,228 Points

You can identify its a method when you see () in front, in this case toLowerCase() is calling a method in the String class. Whereas if its just toLowerCase you are saying to Java its a variable your trying to access.

One way to remember is () is calling a method.

Carlos Federico Puebla Larregle
Carlos Federico Puebla Larregle
21,073 Points

The "()" in "toLowerCase()" represents that "toLowerCase()" is a method instead of being a property. Remember, methods perform actions, properties don't.

Nick Vitsinsky
Nick Vitsinsky
7,246 Points

Thanks, Daniel and *Carlos it clear right now. Now I should understand where to call method and where to call property.