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 trialammarkhan
Front End Web Development Techdegree Student 21,661 PointsWhy have callback as the second argument?
In the video, Andrew made callback the second argument which is confusing for me because in setInterval or setTimeout function, the callback was the first argument the concept is little confusing for me.
2 Answers
Steven Parker
231,261 PointsThere's no specific rule for how to order arguments of a function or method. The setInterval
and setTimout
do similar things, and take the same type of arguments, so it makes sense they would be ordered the same way.
But the function created in the video does something entirely different from either of those, and while one argument is a callback the other is also different. So there's really no reason that the argument order should be related to either of those other functions.
darryn
17,367 PointsAndrew wrote the functions in this video. So he got to choose the order of the arguments.
He didn’t write the setInterval or setTimeout methods.
Those methods are part of JavaScript and are built in for your convenience. Somebody else wrote them.