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

For methods that don't need arguments (.toUpperCase(), toLowerCase()) can you put a parameter inside the parenthesis?

I learned ruby first so these empty parenthesis on the end of these methods feel strange. I understand that they are invoking the function, but is there any situation where you would put something between the parenthesis?

3 Answers

You can put any data type in the parentheses, but nothing different will happen, since those method you mention do not do anything with arguments.

If you go into your console and run 'test'.toUpperCase(true, false, null, 5); everything will work the same as it would if you had left the parens empty.

You can also try entering the following:

function example(){
  return 'my example!';
}

example(1, 2, 3);  // should return 'my example!'

cool, so clear with the test. I am going to try to make tests for little questions moving forward - thanks.

Steven Parker
Steven Parker
243,656 Points

The string you attach it to actually is the first argument (internally it is called this), so putting something inside the parentheses would be giving it a second argument. But it's only defined to use one.

that makes sense, thanks for your help Steven.

I don't think so.I mean what can you put inside the lower case as a parameter? If "foo".toUpperCase(some parameter) is a valid syntax ,I have never seen it yet. And it dosen't say anything in the documentation pages, so answer is probably no.

MDN

Yeah, I couldn't find anything either. Thanks Tushar!