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 trialFarid Lavizadeh
12,006 PointsWhy 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
12,006 PointsI 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
4,989 PointsHey, parseInt() converts a string into a number
Dmitry Polyakov
4,989 PointsIt'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
12,006 PointsAh..Now it makes sense. Thank you Dmitry. :)
Dmitry Polyakov
4,989 PointsYou're welcome!