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 Perfecting: Getting Multiple Profiles

Christopher Johnson
Christopher Johnson
12,829 Points

Few syntax questions

Few short questions:

1. Why is there no '()' required at the end of 'printError'?

2. Can you explain, specifically the {message:x}, the format of: 
'printError({message: 'xyz' + '(' + response.x + ')'});'

3. I'm a little confused with 'module.exports.get = get;'

Thanks for the answers, in advance!

1 Answer

Steven Parker
Steven Parker
229,744 Points

I'll try to answer your questions:

  1. Why is there no '()' required at the end of 'printError'?

When you establish an event handler, you pass it a function, either as an anonymous function defined on the spot, or as the name of a function. You do not want to invoke the function, which would happen if you added the parentheses after the name. It will be invoked later, when the event occurs.

  1. Can you explain, specifically the {message:x}, the format of:
    'printError({message: 'xyz' + '(' + response.x + ')'});'

The printError function expects to be given an object that has a property named error. The brackets here create a temporary anonymous object, and the term message: inside it indicates that it has a property of that name. Following the colon is the content of that property, which is a string built up by concatenating literal strings along with the value represented by response.x.

  1. I'm a little confused with 'module.exports.get = get;'

This just sets the get function (once again, named but not invoked) as a property of module.exports, according to the node convention for making functions exportable.