JavaScript ---- The Global Object
1. The global object is a regular JavaScript object that serves a very important purpose: the properties of this object are the globally defined symbols that are available to a JavaScript program.
When the JavaScript interpreter starts(or whenever a web browser loads a new page), it creates a new global object and gives it an initial set of properties that define:
global properties like
undefined,
Infinity, and
NaN global functions like
isNaN(),
parseInt() and
eval() constructor functions like
Date(),
RegExp(),
String(),
Object(), and
Array() global objects like
Math and
JSON2. In top-level code----JavaScript code that is not part of a function----you can use the JavaScript keyword
this to refer to the global object:
var global = this; // Define a global variable to refer to the global object
3. In client-side JavaScript, the Window object serves as the global object for all JavaScript code contained in the browser window in represents. This global Window object has a self-referential
window property that can be used instead of
this to refer to the global object.