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
Casey Courtney
2,678 PointsFor 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
eck
43,038 PointsYou 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!'
Steven Parker
243,656 PointsThe 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.
Casey Courtney
2,678 Pointsthat makes sense, thanks for your help Steven.
Tushar Singh
Courses Plus Student 8,692 PointsI 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.
Casey Courtney
2,678 PointsYeah, I couldn't find anything either. Thanks Tushar!
Casey Courtney
2,678 PointsCasey Courtney
2,678 Pointscool, so clear with the test. I am going to try to make tests for little questions moving forward - thanks.