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

JavaScript Node.js Basics (2014) Building a Command Line Application Handling Parsing and Status Code Errors

Nils Eriksson
Nils Eriksson
3,396 Points

We don't call printError with a parameter, how does that work ?

we dont add a parameter in request.on("error",printError); but still we can use one, how does that work ?

Also is there any good video explaining how this callback functions work ? how do i create my own? Tnx

1 Answer

Merritt Lawrenson
Merritt Lawrenson
13,477 Points

printError doesn't need a parameter in request.on because you define the parameter when you defined the function earlier. Like Chalkley did in the video, you can insert an anonymous callback function to print the error, but defining the callback function elsewhere makes your code modular, so you can use that callback function for, say, other errors.