I’ve noticed that you can reference a function with or without the parentheses. Why?, what’s the difference?
As a slight aside, I’ve noticed this works:
window.onload = functionName;
Whereas this doesn’t:
window.onload = functionName();
Could anyone explain why the top line of code works and the bottom doesn’t?
The
()version doesn’t reference the function. It invokes the function and references its return value.Given this function:
This references the function:
…but this references the string that was returned, which isn’t very useful to
window.onload: