That's because onload is already declared and null before your script executes.
This is similar to that code :
var v=null;
function v(){
console.log('hi');
}
console.log(v); // alerts null
which is different from this one :
function v(){
console.log('hi');
}
console.log(v); // alerts the function
When you declare a function like this, the declaration and assignment are logically hoisted to the "start" of the scope, so the assignment doesn't really occur after the onload function is given the null value.
That's why it's different from
window.onload=...
which isn't a declaration but only an assignment which can't be hoisted.
That's because onload is already declared and null before your script executes.
This is similar to that code :
var v=null;
function v(){
console.log('hi');
}
console.log(v); // alerts null
which is different from this one :
function v(){
console.log('hi');
}
console.log(v); // alerts the function
When you declare a function like this, the declaration and assignment are logically hoisted to the "start" of the scope, so the assignment doesn't really occur after the onload function is given the null value.
That's because onload is already declared and null before your script executes.
This is similar to that code :
var v=null;
function v(){
console.log('hi');
}
console.log(v); // alerts null
which is different from this one :
function v(){
console.log('hi');
}
console.log(v); // alerts the function
When you declare a function like this, the declaration and assignment are logically hoisted to the "start" of the scope, so the assignment doesn't really occur after the onload function is given the null value.
That's why it's different from
window.onload=...
which isn't a declaration but only an assignment which can't be hoisted.
That's because onload is already declared and null before your script executes.
This is similar to that code :
var v=null;
function v(){
console.log('hi');
}
console.log(v); // alerts null
which is different from this one :
function v(){
console.log('hi');
}
console.log(v); // alerts the function
When you declare a function like this, the declaration and assignment are logically hoisted to the "start" of the scope, so the assignment doesn't really occur after the onload function is given the null value.