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.

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
217,572 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.