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 Iterating and Rendering with map()

How about using " and ' with HTML string?

I'm a bit confused that we don't need to use quote operators inside of {} since it supposes to be JavaScript. Please take a look at my first version of the element App:

const App = (props) => { return( <div className="scoreboard"> <Header title="Scoreboard" totalPlayers={1} /> {/* Players list */} { props.initialPlayers.map(player=> <Player name={player.name} score={player.score} /> )} </div> ); }

Of course, the output is wrong. But I'm still a bit confused about why we don't need to wrap HTML code inside of { } into the quote operators. I hope my question does make sense.

1 Answer

{/* Players list */} is a comment (because of /* */)

<Player name={player.name} score={player.score} these are variables, not strings.

You dynamically assign the value, based on the value of the properties 'name' and 'score' of the player object.

You don't want a string, you want a dynamic value. Hence no quotes. If you'd want a static value you would use quotes (but then why would you need to use react if you want to serve a static page?)