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

Eddie Lam
Eddie Lam
2,681 Points

generateHTML vs generateHTML()

Can someone explain the program flow in each of the scenarios?

1 Answer

Doron Geyer
seal-mask
.a{fill-rule:evenodd;}techdegree
Doron Geyer
Full Stack JavaScript Techdegree Student 13,841 Points

Eddie Lam I will try to explain this as best I can.

with your function getJason it expects certain values.

getJason(url, callback)

so if you pass in generateHTML() what you are doing is you are running the function and trying to pass whatever it returns in. If it has no return it will pass "undefined" . so what you actually end up with is

getJason(url, undefined){
// some code here
undefined(data)
}

when you pass in generateHTML you are passing a reference to the generateHTML() function. so now it looks like this

getJason(url, generateHTML){
// some code here
generateHTML(data)
}

To sum up if you have () at the end you are invoking the function and passing whatever it returns into the expected value. so your value here wouldnt work. expected value !== passed in value.

hope this makes more sense. If this resolved your question please select best answer to mark it resolved.