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 trialMichael Pashkov
22,024 Points<Header title="Scoreboard" totalPlayers={01} />
Hi! who knows, when I place 01 - have a mistake, but when just 1 - it is ok. Why is that?
<Header title="Scoreboard" totalPlayers={01} /> - have a mistake in the browser.
<Header title="Scoreboard" totalPlayers={1} /> - have no mistake.
... const App = () => { return ( <div className="scoreboard"> <Header title="Scoreboard" totalPlayers={1} /> {/* Players list */} <Player /> </div> ); }
ReactDOM.render( <App />, document.getElementById('root') ); ...
2 Answers
Jennifer Nordell
Treehouse TeacherHi there! Preceding zeros in JavaScript can lead to some unexpected consequences as it will interpret that number as octal or a base 8 number instead of a base 10 number. This happens immediately. Take a look at what happens when you run this in the console of your browser:
let x = 01234;
if you then type x
to retrieve the value, it will print back "668". This is the value of the octal number 01234. I've looked at different ways around this and indeed, this is supposed to be deprecated in most browsers, but this still happens. From everything I can find the answer is to make sure your numbers (if you're actually going to use them as numbers) do not contain a leading zero. Alternatively, you could choose to parse the number as a base 10 integer with parseInt(number, 10)
but that seems like a bit of overkill.
Hope this helps!
Michael Pashkov
22,024 PointsThank you Jennifer for your extended reply. It helped indeed.