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 Numbers Working with Numbers Convert Strings to Numbers

Farid Lavizadeh
Farid Lavizadeh
12,006 Points

Why does Guil call parseInt() a method?

Why does Guil call parseInt() a method? Since it doesn't have a receiver object shouldn't it be a function?

4 Answers

Farid Lavizadeh
Farid Lavizadeh
12,006 Points

I understand that. Please let me know if I am correct on followings:

1) string.parseInt() would be a method 2) parseInt(string) would be a function

I am confused. If parseInt() is a method then why is it not used per number 1 above and instead passed as an argument per number 2 above?

When we use toUpperCase() method we don't put the string between parenthesis. Right?

Dmitry Polyakov
Dmitry Polyakov
4,989 Points

Hey, parseInt() converts a string into a number

Dmitry Polyakov
Dmitry Polyakov
4,989 Points

It's method on Number. If you have a string, let's say "1" and save it into a variable num: const num = "1";

The complete statement to convert it into a number will go like this: Number.parseInt(num)

Farid Lavizadeh
Farid Lavizadeh
12,006 Points

Ah..Now it makes sense. Thank you Dmitry. :)