Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
karan BadhwarWeb Development Techdegree Graduate 18,111 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?
Steven Parker220,476 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.