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

Jeffrey Holcomb
seal-mask
.a{fill-rule:evenodd;}techdegree
Jeffrey Holcomb
Full Stack JavaScript Techdegree Student 12,212 Points

What is the meaning of having the "return" keyword in the getJSON function?

I see that the getJSON function is written to return callback(data) if the get request is a success. I've noticed that even if you leave out the return keyword, and just have the function call callback(data) instead of return it, the resulting behavior is the same. I'm looking at the code and trying to understand what the meaning of returning the callback function is, but I can't quite wrap my head around it.

Reggie Williams
seal-mask
.a{fill-rule:evenodd;}techdegree
Reggie Williams
Treehouse Teacher

Hey Jeffrey Holcomb! There is a short section in the teacher's notes below the video about this. Both are acceptable but return provides a way of exiting your function if you need to

1 Answer

Jeffrey Holcomb
seal-mask
.a{fill-rule:evenodd;}techdegree
Jeffrey Holcomb
Full Stack JavaScript Techdegree Student 12,212 Points

Thanks for the clarification Reggie. I hadn't noticed the Teacher's Notes on this video, but I will make sure to double check that next time I'm having a problem understanding something. Cheers!