This is the script that i tested when the page loads.
window.onload = initAll;
function initAll() {
document.getElementById("pTag").innerHTML = "Hello Java Script !";
}
The above script works fine till i put parenthesis like initAll() during the call. _( window.onload=initAll(); )_ . Nothing happens if use initAll() during function call. It is like the script wasn’t there.
Why is it so ?
window.onloadexpects the value you set for it to be a function (functions are like any other object in JavaScript).If you put parens after
initAll, you actually invoke the function and setwindow.onloadto the function’s return value. Since the function does notreturnanything explicitly, this value isundefined. So in practice you can think of this code:as equivalent to this code:
I ‘m sure you can immediately see why this would not work.