Welcome to the Treehouse Community
Looking to learn something new?
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