GlobalNN 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
 
InfinityNaNundefined
 
Methods
 
atob( )btoa( )decodeURI( )
decodeURIComponent( )encodeURI( )encodeURIComponent( )
escape( )eval( )GetObject( )
isFinite( )isNaN( )parseInt( )
parseFloat( )ScriptEngine( )ScriptEngineBuildVersion( )
ScriptEngineMajorVersion( )ScriptEngineMinorVersion( )unescape( )
unwatch( )watch( )
InfinityNN 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

NaNNN 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

undefinedNN 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
 
  • A string containing a relative or complete encoded URI.
 
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
 
  • A string containing base64 data either encoded on the client or received as part of a document from a server that performs its own encoding.
  • A string characters to be encoded to base64 for internal or external use. For example, an encoded value could be assigned to the value property of an input element for submission to a server process designed to receive base64 data.
 
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
 
  • A string containing a relative or complete encoded URI, or portions thereof.
 
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
 
  • A string containing a relative or complete plain-text URI.
 
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
 
  • A string containing a relative or complete plain-text URI, or portions thereof.
 
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
 
  • Any string value.
 
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
 
  • Any string representation of an object reference.
 
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
 
  • A string containing a complete pathname (including volume) to the automation object.
  • Common syntax to reference a particular application and type of object supported by the automation object whose path is specified in the first parameter.
 
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
 
expression

Any JavaScript expression.

 
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
 
expression

Any JavaScript expression.

 
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
 
  • Any string that begins with one or more numerals.
  • An integer of the number base of the number passed as the string parameter (e.g., 2, 8, 10, 16).
 
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
 
  • Any string that begins with one or more numerals.
 
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
 
  • Any URL-encoded string value.
 
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
 
  • The name of the object's property to be watched.
  • The name of the function (no parentheses) to be invoked whenever the watched property's value changes.
 
Returned Value

Nothing.