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 JavaScript Foundations Numbers Parsing Numbers From Strings

Gregor Vollmaier
Gregor Vollmaier
10,986 Points

The octal feature is deprecated

The video talks a lot about the octal feature (if you begin a number string with a 0, it is interpreted as octal by the parseInt() function). However, this feature is deprecated, according to the W3 webpage, and it doesn't behave that way in my Chrome.

With this feature being deprecated, does it still make sense to always use the radix parameter of 10 in the parseInt() function?

1 Answer

Dave McFarland
STAFF
Dave McFarland
Treehouse Teacher

Great question Gregor Vollmaier

The ECMAScript 5 standard says that browsers should default to base 10 and all new browsers do. But, this is the recommendation from the Mozilla Developer's Network:

If the input string begins with "0", radix is eight (octal) or 10 (decimal). Exactly which radix is chosen is implementation-dependent. ECMAScript 5 specifies that 10 (decimal) is used, but not all browsers support this yet. For this reason always specify a radix when using parseInt. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt

The outliers may be still common versions of IE: IE 8, 9. I haven't tested these so I don't now what radix they default to. If anyone here in the forum has access to IE8 and 9 and can quickly check to see what this code alert(parseInt(08)); does, please report back.