Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Do not confuse the head object with global properties or global variables contained within the global scope. The head object is an object that contains all objects. The term “global properties” or “global variables” is used to refer to values directly contained inside the head object and are not specifically scoped to other objects. These values are considered global because no matter where code is currently executing, in terms of scope, all code has access (via the scope chain) to these global properties/variables.
Below, I place a foo property in
the the global scope, then access this property from a different
scope.
<!DOCTYPE html><html lang="en"><body><script> var foo = 'bar'; /* foo is a global object and a property of the head/window object */ var myApp = function() { // remember functions create scope var run = function() { // logs bar, foo's value is found via the scope chain in the head object console.log(foo); }(); } myApp(); </script></body></html>