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 JavaScript Basics (Retired) Making Decisions with Conditional Statements Build a Random Number Guessing Game

Kieran Corcoran
Kieran Corcoran
11,188 Points

JavaScript parseInt() toUpperCase()

Hi,

Not sure how to ask this, but here goes.

Can someone tell me why we pass the argument in the parenthesis when using parseInt(), but when using different methods like toUpperCase() we do not pass it a argument.

For example:

parseInt(somevariable); someVariable.toUpperCase();

Can it work this way round? if not why is this? someVariable.parseInt(); toUpperCase(someVariable);

Many thanks

1 Answer

Steven Parker
Steven Parker
229,644 Points

The "dot" notation selects a method that is associated with object named on the left. In a sense, the item to the left of the dot acts as the first argument to the method. But the implementation is different and not interchangeable.

This may seems a bit confusing at first, but it should become clear when you get further into the classes covering objects and methods. So for now remember that a method must be applied (using dot notation) to an object, but an ordinary function cannot be.