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

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -