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
Sharina Jones
Courses Plus Student 18,771 PointsWhere is callback defined?
I don't understand where callback is defined in the following code. Is this a recursive function call?
'use strict';
function getData({ url, method = 'post' } = {}, callback) {
callback(url, method);
}
getData({ url: 'myposturl.com' }, function (url, method) {
console.log(url, method);
});
1 Answer
Dave StSomeWhere
19,870 PointsThe MDN Callback function might help explain.
So in the example the callback is the function being passed (after the comma)
getData({ url: 'myposturl.com' }, function (url, method) {
console.log(url, method);
Sharina Jones
Courses Plus Student 18,771 PointsSharina Jones
Courses Plus Student 18,771 PointsI see it now, lol! The whole thing just looked so confusing, I couldn't wrap my head around it. Thanks!