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.


In JavaScript why do you place brackets on some function calls and not others? When should you do this?

I just finished the jQuery basic lesson for the form passwords and noticed when some functions were called it used a bracket at the end and other times it did not.

e.g. isPasswordValid() <--bracket $password.focus(passwordEvent) <-- no bracket

Why is this? When should you use each?

Thanks :)

calling function without brackets mean you are passing just a reference to a function & calling function with brackets means you are calling a function not passing a reference....!

suppose you have a function which is responsible for making alert on browser

 function call(){
call;  //no alert window because it is only reference mean it doesn't run
call(); //alert window will be display in browser because you are calling function to run

2 Answers

Aaron Loften
Aaron Loften
8,303 Points

Thats a weird but valid way to write some functions. Conditional statements can be written that way too. I know, it irks me as well. It use to be my old boss' preferred way of doing it.

Thanks Liam.

So using brackets calls a function right away, but without means at some point in future reference this function?