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 2017 Handling Errors in Node Organizing Your Code with require

Michael Pashkov
Michael Pashkov
22,024 Points

Hi, did not get - get. Why get and not get()?

For example, In challenge was question How would you access the functionality from another file?

Given the following code in greeting.js: function sayGreeting() { console.log("Hello World"); }

module.exports.say = sayGreeting;

and write answer was - const greeting = require("./greeting"); greeting.say();

Why in our example users.forEach(profile.get); and not users.forEach(profile.get()); //where get - name of our function

2 Answers

Steven Parker
Steven Parker
231,269 Points

That quiz question is about module exporting, but you seem to be asking about "forEach" syntax. They are not related.

But the "forEach" method takes a function as an argument, and "profile.get" is the name of the function. If you wrote "profile.get()" that would invoke the function and return the result instead of referencing the function itself.