Global | NN 2 IE 3 ECMA 1 | ||||||||||||||||||||
The Global object lives in every window or frame of a JavaScript-enabled browser (it is created for you automatically). You don't ever reference the object explicitly, but you do reference its properties and methods to accomplish tasks such as converting strings to numbers (via the parseInt( ) or parseFloat( ) methods). Properties act as constants, and thus evaluate to themselves. As an object with global scope, it exposes its members to script statements throughout the page. |
|||||||||||||||||||||
Properties | |||||||||||||||||||||
|
|||||||||||||||||||||
Methods | |||||||||||||||||||||
|
Infinity | NN 4 IE 4 ECMA 1 |
Read-only | |
Provides a numerical positive infinity (or negated with the - operator). We're talking a practical, as opposed to a theoretical, infinity here. Any number smaller than Number.MIN_VALUE or larger than Number.MAX_VALUE is an infinite value in the JavaScript world. How mundane! |
|
Example | |
var authorEgo = Infinity; |
|
Value | |
Infinity |
NaN | NN 3 IE 4 ECMA 1 |
Read-only | |
This is a value that is not-a-number. JavaScript returns this value when a numerical operation yields a non-numerical result because of a flaw in one of the operands. If you want to test whether a value is not a number, use the isNaN( ) global function rather than comparing to this property value. This global property is the value that Number.NaN evaluates to. |
|
Value | |
NaN |
undefined | NN 6 IE 5.5(Win) ECMA 2 |
Read-only | |
While the undefined data type has been in ECMAScript and browsers since very early times, only recently was it also elevated to a formal property of the Global object. Despite the recent compatibility ratings, you can use its data type (accessed in string form via the typeof operator) comfortably in older browsers. |
|
Value | |
undefined |
decodeURI( ) | NN 6 IE 5.5(Win) ECMA 3 |
decodeURI("encodedURI") | |
Returns a string with most URI-encoded values in the parameter restored to their original symbols. Operates only on escaped (encoded) characters that are encodable via the encodeURI( ) method. |
|
Parameters | |
|
|
Returned Value | |
A string. |
atob( ), btoa( ) | NN 4 IE n/a ECMA n/a |
atob("base64EncodedData") btoa("stringToBeEncoded") | |
These methods let you convert arbitrary strings (including strings conveying characters representing binary data and Unicode values) to a 65-character subset of the U.S.-ASCII character set. Encoding in this so-called base64 scheme allows any data to be conveyed along even the most rudimentary transport mechanism. You can read about the rationale and internal mechanisms of the encoding/decoding conversions in RFC 1521 of the Internet Engineering Task Force (http://www.ietf.org/rfc/rfc2045.txt). |
|
Use the btoa( ) method to encode string data into the base64 scheme. The resulting encoded data will consist of ASCII characters a-z, A-Z, 0-9, and three symbols (/, +, =). Use the atob( ) method to decode base64 encoded data back to its original version. |
|
Parameters | |
|
|
Returned Value | |
A string. |
decodeURIComponent( ) | NN 6 IE 5.5(Win) ECMA 3 |
decodeURIComponent("encodedURIComponent") | |
Returns a string with all URI-encoded values in the parameter restored to their original symbols. Intended for use on data portions of a URI excluding the protocol. |
|
Parameters | |
|
|
Returned Value | |
A string. |
encodeURI( ) | NN 6 IE 5.5(Win) ECMA 3 |
encodeURI("URIString") | |
Returns a string with most URI-encodable values in the parameter converted to their escaped versions (e.g., a space character is converted to %20). This method excludes the following characters from conversion: ; / ? : @ & = + $ , # |
|
These characters are valid symbols in URI strings as-is, and should not be converted, and the conversion might invalidate the URI. |
|
Parameters | |
|
|
Returned Value | |
A string. |
encodeURIComponent( ) | NN 6 IE 5.5(Win) ECMA 3 |
encodeURIComponent("URIComponentString") | |
Returns a string with all characters except Latin character set letters A through Z (upper and lower cases), digits 0 through 9, and a set of URI-friendly symbols (- _ . ! ~ * ( ) ' space) converted to their escaped versions (% symbol followed by the hexadecimal version of their Unicode value). Intended for use on data portions of a URI excluding the protocol. |
|
Parameters | |
|
|
Returned Value | |
A string. |
escape( ) | NN 2 IE 3 ECMA |1| |
escape("string"[, 1]) | |
Returns a URL-encoded version of the string passed as a parameter to the function. URL encoding converts most nonalphanumeric characters (except * _ + - . / and, in IE, @) to hexadecimal values (such as %20 for the space character). URL-encoded strings do not normally encode the plus symbol because those symbols are used to separate components of search strings. If you must have the plus symbol encoded as well, Navigator 4 (only) offers a second parameter (a numeral 1) to turn on that switch for the method. Note that in IE 5.5 for Windows and Netscape 6, this method has been deprecated in favor of the encodeURI( ) and encodeURIComponent( ) methods. This method has been removed from the ECMA 3 specification. |
|
Parameters | |
|
|
Returned Value | |
A string. |
eval( ) | NN 2 IE 3 ECMA 1 |
eval("string") | |
Returns an object reference of the object described as a string in the parameter of the function. For example, if a form has a sequence of text fields named entry1, entry2, entry3, and so on, you can still use a for loop to cycle through all items by name if you let the eval( ) function convert the string representation of the names to object references: for (var i = 1; i<=5; i++) { oneField = eval("document.forms[0].entry" + i); oneValue = oneField.value; ... } |
|
Be aware, however, that the eval( ) method is perhaps the most inefficient and performance-draining method of the entire JavaScript language. There are many other, far more efficient, ways to reference a document tree object when you have only the string ID or name, such as the document.getElementById( ) and, for older browsers, named indexes of the document.forms, document.images, and document.formRef.elements arrays. |
|
Parameters | |
|
|
Returned Value | |
Object reference. |
GetObject( ) | NN n/a IE 5(Win) ECMA n/a |
GetObject("localPathName"[, appName.objectType]) | |
Returns a reference to an ActiveX object hosted on the client machine whose path name the script is aware of. This is an alternate to creating an instance of an ActiveXObject. In addition to specifying the pathname of the control, you can name a data file to open along with the control's application. Append an exclamation point and the name of the file as part of the localPathName parameter. To learn more about invoking ActiveX objects (also called automation objects), visit: http://msdn.microsoft.com/scripting/jscript/doc/jsobjActiveXObject.htm. |
|
Parameters | |
|
|
Returned Value | |
Object reference. |
isFinite( ) | NN 4 IE 4 ECMA 1 |
isFinite(expression) | |
Returns a Boolean value of true if the number passed as a parameter is anything within the range of Number.MIN_VALUE and Number.MAX_VALUE, inclusive. String values passed as parameters cause the function to return false. |
|
Parameters | |
|
|
Returned Value | |
Boolean value: true | false. |
isNaN( ) | NN 2 IE 3 ECMA 1 |
isNaN(expression) | |
Returns a Boolean value of true if the expression passed as a parameter does not evaluate to a numeric value. Any expression that evaluates to NaN (such as performing parseInt( ) on a string that does not begin with a numeral) causes the isNaN( ) method to return true. |
|
Parameters | |
|
|
Returned Value | |
Boolean value: true | false. |
parseInt( ) | NN 2 IE 3 ECMA 1 |
parseInt("string "[, radix]) | |
Returns an integer value (as a number data type in base-8 or base-10) of the numerals in the string passed as a parameter. The string value must at least begin with a numeral, or the result is NaN. If the string starts with numbers but changes to letters along the way or includes white space, only the leading numbers up to the first nonnumeral or whitespace are converted to the integer. Therefore, you can use the expression: parseInt(navigator.appVersion) |
|
to extract only the whole number of the version that leads the otherwise long string that is returned from that property. |
|
The optional radix parameter lets you specify the base of the number being passed to the function. A number string that begins with zero is normally treated as an octal number, which gives you the wrong answer. It is a good idea to use the radix value of 10 on all parseInt( ) functions if all of your dealings are in base-10 numbers. |
|
Parameters | |
|
|
Returned Value | |
Integer. |
parseFloat( ) | NN 2 IE 3 ECMA 1 |
parseFloat(string) | |
Returns a number value (either an integer or floating-point number) of the numerals in the string passed as a parameter. The string value must at least begin with a numeral, or the result is NaN. If the string starts with numbers but changes to letters along the way, only the leading numbers are converted to the integer. Therefore, you can use the expression: parseFloat(navigator.appVersion) |
|
to extract the complete version number (e.g., 4.03) that leads the otherwise long string that is returned from that property. |
|
If the converted value doesn't have any nonzero values to the right of the decimal, the returned value is an integer. Floating-point values are returned only when the number calls for it. |
|
Parameters | |
|
|
Returned Value | |
Number. |
ScriptEngine( ), ScriptEngineBuildVersion( ), ScriptEngineMajorVersion( ), ScriptEngineMinorVersion( ) | NN n/a IE 4 ECMA n/a |
These Internet Explorer-only functions reveal information about the scripting engine (JScript, VBScript, or VBA) being used to invoke the method and which version of that engine is installed. For JScript, the version refers to the version of the Jscript.dll file installed among the browser's support files. The major version is the part of the version number to the left of the version decimal point; the minor version is the part to the right of the decimal point. More granular than that is the internal build number that Microsoft uses to keep track of release generations during development and through release. |
|
Parameters | |
None. |
|
Returned Value | |
ScriptEngine( ) returns a string of one of the following engine names: JScript | VBA | VBScript. All other functions return integer values. |
unescape( ) | NN 2 IE 3 ECMA |1| |
unescape(string) | |
Returns a decoded version of the URL-encoded string passed as a parameter to the function. URL encoding converts nonalphanumeric characters (except * _ + - . / and, in IE, @) to hexadecimal values (such as %20 for the space character). Note that in IE 5.5 for Windows and Netscape 6, this method has been deprecated in favor of the decodeURI( ) and decodeURIComponent( ) methods. This method has been removed from the ECMA 3 specification. |
|
Parameters | |
|
|
Returned Value | |
String. |
unwatch( ), watch( ) | NN 4 IE n/a ECMA n/a |
unwatch(property) watch(property, funcHandler) | |
These Navigator-specific functions are used primarily by JavaScript debuggers. When a statement invokes the watch( ) function for an object, the parameters include the property whose value is to be watched and the reference to the function to be invoked whenever the value of the property is changed by an assignment statement. To turn off the watch operation, invoke the unwatch( ) function for the particular property engaged earlier. |
|
Parameters | |
|
|
Returned Value | |
Nothing. |