Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Asynchronous Programming with JavaScript!

- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
Now that we're successfully getting data asynchronously from the Open Notify API, let's use it to make another AJAX call, this time to the Wikipedia API.
Why return callback()
vs. only callback()
?
Both are perfectly acceptable. In fact, most of the time you might use:
if(xhr.status === 200) {
let data = JSON.parse(xhr.responseText);
callback(data);
}
instead of:
if(xhr.status === 200) {
let data = JSON.parse(xhr.responseText);
return callback(data);
}
In this case, it's using return
to ensure that execution in the current scope does not continue past invoking callback(data)
. This might prevent multiple callbacks from being accidentally invoked, for example. In any case, it provides a clear way of short-circuiting the function you're in.
Resources
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
Crystal Vesely
14,503 Points2 Answers
-
Crystal Vesely
14,503 Points1 Answer
-
Gavin Eyquem
Front End Web Development Techdegree Student 22,115 Points1 Answer
-
Katarzyna Russek
6,086 Points2 Answers
-
shaker owusu
30 Points1 Answer
-
Ash Borkar
1,738 PointsIs the astrosUrl out of date? I get an error saying the request made to that API is an insecure request.
Posted by Ash BorkarAsh Borkar
1,738 Points4 Answers
-
Samuel Kleos
Front End Web Development Techdegree Student 13,728 Points0 Answers
-
amarpreet singh saluja
1,053 Points1 Answer
-
Marni Ali
4,642 Points1 Answer
-
Ludvig Boysen
4,236 Points1 Answer
-
Terry Babyuk
9,231 Points10 Answers
-
Jeffrey Holcomb
Full Stack JavaScript Techdegree Graduate 17,506 Points1 Answer
-
Heather Cloward
6,506 Points1 Answer
-
Kirt Perez
7,374 Points2 Answers
-
trottly
5,394 Points1 Answer
-
Zaid Khan
12,769 Points6 Answers
View all discussions for this video
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up