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

parseInt() only converts the string to a number momentarily?

On the following exercise this caused me issues, because i ordered the parseInt, independently from the calculation. Then I realized that parseInt must be present at the time of the calculation, otherwise it is treated as a string.

Therefore my assessment is that parseInt doesn't convert the string to a number definitely. Is there any method to do so?

1 Answer

Michael Hulet
Michael Hulet
47,913 Points

parseInt doesn't modify the data you pass it in-place. Rather, it takes the string you give it, leaves it be in its variable/constant, and returns a numerical value if one could be parsed. Just like any JavaScript data, you can hang onto this as long as you want if you save it in its own variable/constant, though you could use it and discard it immediately if you prefer