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

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,074 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,074 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.