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 trialObe Juarez
6,357 PointsIs 'callback' just a sort of variable name, or does is it actually a JS special keyword?
Im having a hard time understanding if 'callback' is actually a special word in JS? for example: function name(a, b, user) {
} can I just input my own variable or does it have to be callback because callback is actually a method of sorts?
1 Answer
Clayton Perszyk
Treehouse Moderator 48,850 PointsYou can name callback whatever you want. It's not a reserved keyword. All that is required is that you pass a function that can be "called" after task is complete.
Obe Juarez
6,357 PointsObe Juarez
6,357 PointsClayton Perszyk Ok so, lets say I have like 5 parameters inside a function, the last parameter isn't necessarily the function right, I can have the function in the third perimeter if I wanted to?
Clayton Perszyk
Treehouse Moderator 48,850 PointsClayton Perszyk
Treehouse Moderator 48,850 PointsObe Juarez Actually all parameters must be passed in the correct order. If the callback is the last, you will need to pass a callback function. The 3rd parameter COULD be a callback, but it would be based on how the function was written. The convention and best practice is to have the callback as the last parameter.