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 Callbacks Review

italiandadx2
italiandadx2
3,566 Points

I don't understand why (sum) is used.

The function add is asking for 3 arguments one of those being a function. I understand that much... What I do not get is when the add function is invoked the function being passed as the third argument has an argument of sum...?

3 Answers

Reggie Williams
STAFF
Reggie Williams
Treehouse Teacher

Hey italiandadx2 ! function(sum) is the third argument. The function has the argument of sum because it's anonymous and doesn't have another definition. Because we see sum as an argument of the function we know that the value passed in will be passed as well in place of the word sum inside the function

Joseph Quintiliano
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Joseph Quintiliano
Front End Web Development Techdegree Graduate 14,338 Points

the reason the variable 'sum' is there, is because the add's parameters is basically saying,

"(we'll take this number), (we'll take this number), and (this is where the answer/sum will be)"

The function 'add' has a 3rd argument which is the anonymous function. The 'add' function calls this anonymous function and passes in a single argument (a + b). Therefore, it seems to me like an argument is passed and within it another argument. In other words, an argument within an argument. It's a tough concept for me to grasp even with this very simple example!