I’m learning javascript and noticed the following two syntaxes achieve the same end goal:
window.alert("chitty chitty bang bang!");
alert("chitty chitty bang bang!");
Also, why doesn’t this syntax work?
window.document.alert("chitty chitty bang bang!");
windowis kind of the global scope of javascript. If you don’t specify a scope when calling a javascript function, this parent global scope is always assumed. As far as whywindow.document.alertdoesn’t work is concerned, well, it’s because thealertfunction has been defined on thewindowglobal object and not on thewindow.documentobject which represents the DOM.