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 JavaScript Array Iteration Methods Array Manipulation Remove Array Items with filter()

karan Badhwar
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
karan Badhwar
Web Development Techdegree Graduate 18,135 Points

How filter() or setTimeout() methods invoke functions without parenthesis

As we just pass in the name of the variable holding the function, but how does they invoke it, generally we pass that via parenthesis, but how this happens?

And how to tell where do I need to add Parenthesis and where not?

1 Answer

Steven Parker
Steven Parker
231,269 Points

A "callback" argument is a reference to a function. You are not actually calling the function when you pass the reference.

At a later time, the system will invoke the function by using parentheses. This happens in internal code that you don't actually see.

So, you use parentheses when you want to invoke the function yourself and pass along whatever that function returns. But you do not use parentheses when you want to pass a reference to the function itself.