When I set the onload property I use
window.onload=initialize_page;
However,
when I use undefined, which I understand is a window property I simply use:
undefined
How do I know when to scope properties?
If I remove window from the first statement it works. I guess I’ve seen both in code here on SO, but which way is best practice?
When you want to define a global variable, it’s recommended to prefix
window., to prevent conflicts with local variables with the same name.For example, Rocket (at the OP’s comments) suggested to use
onload=initialize_page;instead ofwindow.onload = .... This will fail in the following case:If you encounter a variable, and don’t know whether it’s a global variable or not, you can use the following code to determine it: