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 trialkaran Badhwar
Web Development Techdegree Graduate 18,135 PointsHow 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
231,236 PointsA "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.
karan Badhwar
Web Development Techdegree Graduate 18,135 Pointskaran Badhwar
Web Development Techdegree Graduate 18,135 PointsThankyou Steven Parker, you are full of Knowledge, how come You know everything and remember it too
Steven Parker
231,236 PointsSteven Parker
231,236 PointsI've been a software developer for a very long time. Lots of practice!
karan Badhwar
Web Development Techdegree Graduate 18,135 Pointskaran Badhwar
Web Development Techdegree Graduate 18,135 PointsSteven Parker I hope I become a great developer like you