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
Molly BarCourses Plus Student 5,925 Points
Parsing 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..
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
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.
Number.parseInt() which acts exactly the same as the global