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 Asynchronous Programming with JavaScript Asynchronous JavaScript with Callbacks Implement a Callback

question about the syntax

I understood the structure of the getJSON function but this line trip me off:

getJSON(astrosUrl, (json) => {
    json.people.map(person => {
      getJSON(wikiUrl + person.name, generateHTML);
    });
  });

in the first call to the getJSON function we provide a url like getJSON function required but then we need to provide a callback. I didnt understand what is going on in this line:

 (json) => {

instead of calling a function we are calling an anonymous function? and "json" is the parameter which holds the data?

1 Answer

Dmitry Polyakov
Dmitry Polyakov
4,989 Points

Hey. We are calling an anonymous function that loops through all people one by one with .map method. Here the parameter is called json, but it can have any other name.

For example:

getJSON(astrosUrl, (tempParameter) => {

tempParameter.people.map(person => {

  getJSON(wikiUrl + person.name, generateHTML);

});

});

Milena Zhang
Milena Zhang
6,641 Points

i don't understand where we get person and people from. is "person" only a random name we assign to the function?