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

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,897 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.