Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript React Basics Introducing Props Setting and Using Props

Michael Pashkov
Michael Pashkov
22,023 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
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi 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! :sparkles:

Michael Pashkov
Michael Pashkov
22,023 Points

Thank you Jennifer for your extended reply. It helped indeed.