JavaScript global reference manual

JavaScript global properties and functions can be used with all built-in JavaScript objects.

JavaScript global property

Property Description
Infinity Represents a number that is positive or negative infinity.
NaN The value 'Not-a-Number' (NaN).
undefined Represents a variable that has not been assigned a value.

JavaScript global function

Function Description
decodeURI() Decode URI.
decodeURIComponent() Decode URI components.
encodeURI() Encode URI.
encodeURIComponent() Encode URI components.
escape() Deprecated in version 1.5.Please use encodeURI() Or encodeURIComponent() Instead.
eval() Evaluate a string and execute it as script code.
isFinite() Determine whether a value is a finite and valid number.
isNaN() Determine whether a value is an illegal number.
Number() Convert the value of an object to a number.
parseFloat() Parse a string and return a floating-point number.
parseInt() Parse a string and return an integer.
String() Convert the value of an object to a string.
unescape() Deprecated in version 1.5.Please use decodeURI() Or decodeURIComponent() Instead.

Function or method?

It makes sense to call the global functions listed above instead of global methods because functions are globally invoked, not associated with any object.

In any case, you can also call these function methods because they are methods of the global object in their runtime environment. In a web browser, the global object is the browser window. So isNaN() is actually a window method: window.isNaN().

Description of the global object

The global object is a predefined object that acts as a placeholder for JavaScript's global functions and global properties. By using the global object, you can access all other predefined objects, functions, and properties. The global object is not a property of any object, so it has no name.

In top-level JavaScript code, the keyword this can be used to refer to the global object. However, it is usually not necessary to use this method to refer to the global object, because the global object is the head of the scope chain, which means that all non-qualified variables and function names will be queried as properties of this object. For example, when JavaScript code refers to the parseInt() function, it refers to the parseInt property of the global object. The global object being the head of the scope chain also means that all variables declared in top-level JavaScript code will become properties of the global object.

The global object is just an object, not a class. It has no constructor and cannot instantiate a new global object.

When JavaScript code is embedded in a special environment, the global object usually has environment-specific properties. In fact, the ECMAScript standard does not specify the type of the global object, and the implementation of JavaScript or embedded JavaScript can take any type of object as the global object, as long as the object defines the basic properties and functions listed here. For example, in a JavaScript implementation that allows scripting Java through LiveConnect or related technologies, the global object is given the java and Package properties as well as the getClass() method listed here. In client-side JavaScript, the global object is the Window object, representing the web browser window that allows JavaScript code to run.

Example

In the core language of JavaScript, the predefined properties of the global object are non-enumerable. All implicitly or explicitly declared global variables can be listed using the for/in loop, as shown below:

var variables = "";
for (var name in this) 
{
variables += name + "<br />";
}
document.write(variables);

Try It Yourself