In JavaScript, does it make a difference if I call a function with parentheses? -


i noticed difference when calling function empty parentheses, or without parentheses @ all. however, not passing arguments function wondered, difference between:

window.onload = initall(); 

and

window.onload = initall; 

please explain principle behind it.

window.onload = initall(); 

this executes initall() straight away , assigns function's return value window.onload. not want. initall() have return function make sense.

window.onload = initall; 

this assigns actual function window.onload - possible because in javascript, @felix says, functions first class objects - without executing it. initall executed load event.


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

post - imageshack API cURL -