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 One Solution

planets.map(planet => createPlanetHTML(planet)).join('');

I get that planets.map makes a new array, that contains the result of passing both objects properties through the following function

createPlanetHtml()

But...

planets.map(planet => createPlanetHTML(planet)).join('');
//            ^ planet                    ^ planet again

What is happening with the planet parameter in this instance and what is being passed to it for this to work?

1 Answer

Hi Carl Dawkins,

In the example you provided

planets.map(planet => createPlanetHTML(planet)).join('');
//            ^ planet                    ^ planet again

The "planet" in reference is the argument. Since we're using the arrow function, this variable can be named anything you like. To see a more traditional format, I believe you can interpret it like this:

planets.map(
   function(planet) {
      return createPlanetHTML(planet);
   }
).join('');

It's a function within a function.

Hope this helps clarify things a little more.