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 trialMolly Bar
Courses Plus Student 5,925 PointsParsing Numbers From Strings problem - I think this tutorial is obsolete.
I do not have to put base 10 anymore. when I type the variable in the console, I am getting the # i am looking for without base 10. Also, When I put 23 people, I am getting 23 on the console , not "NaN" (not a number). I wonder how old this tutorial is..
1 Answer
Dino Paškvan
Courses Plus Student 44,108 PointsHello, Molly,
Take a look at the Teacher's Notes under that video. They explain that the default behaviour of parseInt()
has now changed. By default, it now assumes the radix is 10
, not 8
. But passing the radix to the parseInt()
function isn't just about getting your code to work, it's also about code readability. Someone else might end up reading code you've written and an explicit radix shows that you are fully aware of the workings of that function.
This change is part of the ECMAScript 5 standard but some implementations still haven't allowed it, so for full compatibility, you should always specify a radix. You can take a look at the documentation on MDN that confirms this.
Finally, if you watch the video again, you'll see that Jim is also getting a number for the string "23 people"
. However, he gets NaN
back for the string "there are 23 people"
— a string that doesn't start with a number. That behaviour did not change and isn't likely to change.
In fact, ES6, the upcoming standard of JavaScript, defines a new method Number.parseInt()
which acts exactly the same as the global parseInt()
function.