AL-zami AL-zami - 1 year ago 93
Javascript Question

Two confusing statements, which one to use and why?

I am confused about these two statements. Both are giving two different results. For simplification I am not posting full code here. The key point is I want to know the difference between the two. say, I want to invoke a function when I scroll the page. What is the difference between using a parentheses and not using a parentheses in this statement?




Answer Source

With parenthesis means: run the function and return the result.

Without parenthesis means: use the function itself.

So if you want to bind a function to the "onscroll" event, you do NOT want parenthesis. For example, if your function returns "2", then


would be the same as


which wouldn't make sense.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download