Browser/User Agent Support
| IE | Mozilla | Netscape | Opera | Safari | 3.0+ | 1.0+ | 2.0+ | 7.0+ | no |
|---|
Constructors
| Constructor | IE | Mozilla | Netscape | Opera | Safari |
|---|---|---|---|---|---|
The Global object does not have a constructor. | 3.0+ | 1.0+ | 2.0+ | 7.0+ | no |
Properties
| Property | IE | Mozilla | Netscape | Opera | Safari |
|---|---|---|---|---|---|
A numeric value representing infinity. | 4.0+ | 1.0+ | 4.06+ | 7.0+ | 1.0+ |
A value representing Not-a-Number. | 4.0+ | 1.0+ | 4.06+ | 7.0+ | 1.0+ |
The value undefined. | 5.5+ | 1.0+ | 4.06+ | 7.0+ | 1.0+ |
Methods
| Method | IE | Mozilla | Netscape | Opera | Safari |
|---|---|---|---|---|---|
Decodes a Uniform Resource Identifier (URI) previously created by encodeURI or by a similar routine. | 5.5+ | 1.0+ | 6.0+ | 7.0+ | no |
Decodes a Uniform Resource Identifier (URI) component previously created by encodeURIComponent or by a similar routine. | 5.5+ | 1.0+ | 6.0+ | 7.0+ | no |
Encodes a Uniform Resource Identifier (URI) by replacing each instance of certain characters by one, two, or three escape sequences representing the UTF-8 encoding of the character. | 5.5+ | 1.0+ | 6.0+ | 7.0+ | no |
Encodes a Uniform Resource Identifier (URI) component by replacing each instance of certain characters by one, two, or three escape sequences representing the UTF-8 encoding of the character. | 5.5+ | 1.0+ | 6.0+ | 7.0+ | no |
Returns a URI-encoded version of a string. | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ |
Evaluates a string of JavaScript code without reference to a particular object. | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ |
Evaluates whether an argument is a finite number. | 4.0+ | 1.0+ | 4.06+ | 7.0+ | 1.0+ |
Evaluates whether an argument is NaN. | 4.0+ | 1.0+ | 3.0+ | 7.0+ | 1.0+ |
Parses a string and returns its value as a number. | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ |
Parses a string argument and returns an integer of the specified radix or base. | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ |
Returns a URI-decoded version of a string. | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ |
Availability
JavaScript 1.0 | JScript 1.0 | ECMAScript v1
Constructor Detail
Property Detail
static Infinity Infinity - only
A numeric value representing infinity.
- Remarks
-
Infinityis a property of the global object, i.e. it is a variable in global scope.The initial value of
InfinityisNumber.POSITIVE_INFINITY. The valueInfinity(positive infinity) is greater than any other number including itself. This value behaves mathematically like infinity; for example, anything multiplied byInfinityisInfinity, and anything divided byInfinityis 0. - See Also
- Availability
JavaScript 1.3 | JScript 3.0 | ECMAScript v1
NaN NaN - only
A value representing Not-a-Number.
- Remarks
-
NaNis a property of the global object, i.e. it is a variable in global scope.The initial value of
NaNis Not-A-Number - the same as the value of Number.NaN.NaNis always unequal to any other number, includingNaNitself; you cannot check for the not-a-number value by comparing toNumber.NaN. Use theisNaNfunction instead.Several JavaScript methods (such as the
Numberconstructor,parseFloat, andparseInt) returnNaNif the value specified in the parameter can not be parsed as a number.You might use the
NaNproperty to indicate an error condition for your function that returns a number in case of success.JavaScript prints the value
Number.NaNasNaN. - See Also
- Availability
JavaScript 1.3 | JScript 3.0 | ECMAScript v1
undefined undefined - only
The value undefined.
- Remarks
-
undefinedis a property of the global object, i.e. it is a variable in global scope.The initial value of
undefinedis the primitive valueundefined.A variable that has not been assigned a value is of type undefined. A method or statement also returns
undefinedif the variable that is being evaluated does not have an assigned value. A function returnsundefinedif a value was not returned.You can use
undefinedand the strict equality operator to determine whether a variable has a value. In the following code, the variablexis not defined, and theifstatement evaluates to true.var x; if (x === undefined) { // these statements execute }Note: The strict equality operator rather than the standard equality operator must be used here, because
x == undefinedalso checks whetherxisnull, while strict equality doesn't.nullis not equivalent toundefined. See comparison operators for details.Alternatively, typeof can be used:
var x; if (typeof x == 'undefined') { // these statements execute } - Availability
JavaScript 1.3 | JScript 5.5 | ECMAScript v1
Method Detail
decodeURI(String encodedURI) : String
Decodes a Uniform Resource Identifier (URI) previously created by encodeURI or by a similar routine.
| String | encodedURI | A complete, encoded Uniform Resource Identifier. |
- Remarks
-
Replaces each escape sequence in the encoded URI with the character that it represents.
Does not decode escape sequences that could not have been introduced by
encodeURI. - See Also
- Availability
JavaScript 1.5 | JScript 5.5 | ECMAScript v3
decodeURIComponent(String encodedURI) : String
Decodes a Uniform Resource Identifier (URI) component previously created by encodeURIComponent or by a similar routine.
| String | encodedURI | An encoded component of a URI. |
- Remarks
- Replaces each escape sequence in the encoded URI component with the character that it represents.
- See Also
- Availability
JavaScript 1.5 | JScript 5.5 | ECMAScript v3
encodeURI(String URI) : String
Encodes a Uniform Resource Identifier (URI) by replacing each instance of certain characters by one, two, or three escape sequences representing the UTF-8 encoding of the character.
| String | URI | A complete Uniform Resource Identifier. |
- Remarks
-
Assumes that the URI is a complete URI, so does not encode reserved characters that have special meaning in the URI.
encodeURIreplaces all characters except the following with the appropriate UTF-8 escape sequences:Type Includes Reserved characters ; , / : @ & = + $Unescaped characters alphabetic, decimal digits, - _ . ! ~ * ' ( )Score #Note that
encodeURIby itself cannot form proper HTTP GET and POST requests, such as for XMLHTTPRequests, because "&", "+", and "=" are not encoded, which are treated as special characters in GET and POST requests.encodeURIComponent, however, does encode these characters. These behaviors are most likely not consistent across browsers. - See Also
- Availability
JavaScript 1.5 | JScript 5.5 | ECMAScript v3
encodeURIComponent(String String) : String
Encodes a Uniform Resource Identifier (URI) component by replacing each instance of certain characters by one, two, or three escape sequences representing the UTF-8 encoding of the character.
| String | String | A component of a Uniform Resource Identifier. |
- Remarks
-
encodeURIComponent escapes all characters except the following: alphabetic, decimal digits,
- _ . ! ~ * ' ( )For security reasons, you should call encodeURIComponent on any user-entered parameters that will be passed as part of a URI. For example, a user could type "Thyme &time=again" for a variable
comment. Not using encodeURIComponent on this variable will givecomment=Thyme%20&time=again. Note that the ampersand and the equal sign mark a new key and value pair. So instead of having a POSTcommentkey equal to "Thyme &time=again", you have two POST keys, one equal to "Thyme " and another (time) equal to again. This is super, super, super dangerous if you are using PHP with register_globals turned on. - See Also
- Availability
JavaScript 1.5 | JScript 5.5 | ECMAScript v3
escape(string string) : String
Returns a URI-encoded version of a string.
| string | string | String to be URI-encoded. |
- Remarks
- escape has been phased out in favor of encodeURIComponent.
- See Also
- Availability
JavaScript 1.0 | JScript 1.0
eval(String string) : BooleanNumberObjectString
Evaluates a string of JavaScript code without reference to a particular object.
| String | string | A string representing a JavaScript expression, statement, or sequence of statements. string can include variables and properties of existing objects. |
-
The following examples display output using
document.write. In server-side JavaScript, you can display the same output by calling thewritefunction instead of usingdocument.write.Example: Using
evalIn the following code, both of the statements containing
evalreturn 42. The first evaluates the string "x + y + 1"; the second evaluates the string "42".var x = 2; var y = 39; var z = "42"; eval("x + y + 1"); // returns 42 eval(z); // returns 42Example: Using
evalto evaluate a string of JavaScript statementsThe following example uses
evalto evaluate the stringstr. This string consists of JavaScript statements that open an Alert dialog box and assignza value of 42 ifxis five, and assigns 0 tozotherwise. When the second statement is executed,evalwill cause these statements to be performed, and it will also evaluate the set of statements and return the value that is assigned toz.var str = "if (x == 5) {alert('z is 42'); z = 42;} else z = 0; "; document.write("z is ", eval(str));
- Remarks
-
evalis a top-level function and is not associated with any object.The argument of the
evalfunction is a string. If the string represents an expression,evalevaluates the expression. If the argument represents one or more JavaScript statements,evalperforms the statements. Do not callevalto evaluate an arithmetic expression; JavaScript evaluates arithmetic expressions automatically.If you construct an arithmetic expression as a string, you can use
evalto evaluate it at a later time. For example, suppose you have a variablex. You can postpone evaluation of an expression involvingxby assigning the string value of the expression, say "3 * x + 2", to a variable, and then callingevalat a later point in your script.If the argument of
evalis not a string,evalreturns the argument unchanged. In the following example, theStringconstructor is specified, andevalreturns aStringobject rather than evaluating the string.eval(new String("2+2")); // returns a String object containing "2+2" eval("2+2"); // returns 4You cannot indirectly use the
evalfunction by invoking it via a name other thaneval; if you do, a runtime error might occur. For example, you should not use the following code:var x = 2; var y = 4; var myEval = eval; myEval("x + y");You should not use
evalto convert property names into properties. For example, consider the following example. ThegetFieldName(n)function returns the name of the specified form element as a string. The first statement assigns the string value of the third form element to the variablefield. The second statement usesevalto display the value of the form element.var field = getFieldName(3); document.write("The field named ", field, " has value of ", eval(field + ".value"));However
evalis not necessary here. In fact, its use here is discouraged. Instead, use the member operators, which are much faster:var field = getFieldName(3); document.write("The field named ", field, " has value of ", field[value]);Backward Compatibility
JavaScript 1.3 and earlier
You can use
evalindirectly, although it is discouraged.JavaScript 1.1
evalis also a method of all objects. - Availability
JavaScript 1.0 | JScript 1.0 | ECMAScript v1
isFinite(Number number) : Boolean
Evaluates whether an argument is a finite number.
| Number | number | Number to be evaluated. |
-
Example: Using
isFiniteYou can check a client input to determine whether it is a finite number.
if (isFinite(ClientInput)) { /* take specific steps */ } - Remarks
-
isFiniteis a top-level function and is not associated with any object.You can use this method to determine whether a number is a finite number. The
isFinitemethod examines the number in its argument. If the argument isNaN, positive infinity or negative infinity, this method returnsfalse, otherwise it returnstrue. - See Also
- Availability
JavaScript 1.3 | JScript 3.0 | ECMAScript v1
isNaN(String value) : Boolean
Evaluates whether an argument is NaN.
| String | value | The value you want to evaluate. |
-
Example: Using
isNaNThe following example evaluates
floatValueto determine if it is a number, and then calls a procedure accordingly:floatValue = parseFloat(toFloat); if (isNaN(floatValue)) { notFloat(); } else { isFloat(); } - Remarks
-
isNaNis a top-level function and is not associated with any object.The
parseFloatandparseIntfunctions returnNaNwhen they evaluate a value that is not a number.isNaNreturnstrueif passedNaN, andfalseotherwise.This function is necessary, because the value
NaNcannot be meaningfully tested with the equality operators.x == NaNandx === NaNare always false, regardless of whatxis, even ifxisNaN. For example, both1 == NaNandNaN == NaNreturnfalse. - See Also
- Availability
JavaScript 1.1 | JScript 3.0 | ECMAScript v1
parseFloat(String string) : Number
Parses a string and returns its value as a number.
| String | string | A string that represents the value you want to parse. |
-
Example:
parseFloatreturning a numberThe following examples all return 3.14:
parseFloat("3.14");parseFloat("314e-2");parseFloat("0.0314E+2");var x = "3.14";parseFloat(x);parseFloat("3.14more non-digit characters");
Example:
parseFloatreturning NaNThe following example returns
NaN:parseFloat("FF2");
- Remarks
-
parseFloatis a top-level function and is not associated with any object.parseFloatparses its argument, a string, and returns a floating point number. If it encounters a character other than a sign (+ or -), numeral (0-9), a decimal point, or an exponent, it returns the value up to that point and ignores that character and all succeeding characters. Leading and trailing spaces are allowed.If the first character cannot be converted to a number,
parseFloatreturnsNaN.For arithmetic purposes, the
NaNvalue is not a number in any radix. You can call theisNaNfunction to determine if the result ofparseFloatisNaN. IfNaNis passed on to arithmetic operations, the operation results will also beNaN. - See Also
- Availability
JavaScript 1.0 | JScript 1.0 | ECMAScript v1
parseInt(String string, [Number radix]) : Number
Parses a string argument and returns an integer of the specified radix or base.
| String | string | A string that represents the value you want to parse. |
| Number | radix | An integer that represents the radix of the above mentioned string. (optional) |
-
Example: Using
parseIntThe following examples all return 15:
parseInt("F", 16);parseInt("17", 8);parseInt("15", 10);parseInt(15.99, 10);parseInt("FXX123", 16);parseInt("1111", 2);parseInt("15*3", 10);parseInt("12", 13);
The following examples all return
NaN:parseInt("Hello", 8); // Not a number at allparseInt("0x7", 10); // Not in base 10 formatparseInt("546", 2); // Digits are not valid for binary representations
Even though the radix is specified differently, the following examples all return 17 because the input
stringbegins with "0x".parseInt("0x11", 16);parseInt("0x11", 0);parseInt("0x11");
- Remarks
-
parseIntis a top-level function and is not associated with any object.The
parseIntfunction parses its first argument, a string, and attempts to return an integer of the specified radix (base). For example, a radix of 10 indicates to convert to a decimal number, 8 octal, 16 hexadecimal, and so on. For radixes above 10, the letters of the alphabet indicate numerals greater than 9. For example, for hexadecimal numbers (base 16), A through F are used.If
parseIntencounters a character that is not a numeral in the specified radix, it ignores it and all succeeding characters and returns the integer value parsed up to that point.parseInttruncates numbers to integer values. Leading and trailing spaces are allowed.If the radix is not specified or is specified as 0, JavaScript assumes the following:
- If the input
stringbegins with "0x", the radix is 16 (hexadecimal).
- If the input
stringbegins with "0", the radix is eight (octal). This feature is deprecated.
- If the input
stringbegins with any other value, the radix is 10 (decimal).
If the first character cannot be converted to a number,
parseIntreturnsNaN.For arithmetic purposes, the
NaNvalue is not a number in any radix. You can call theisNaNfunction to determine if the result ofparseIntisNaN. IfNaNis passed on to arithmetic operations, the operation results will also beNaN. - If the input
- See Also
- Availability
JavaScript 1.0 | JScript 1.0 | ECMAScript v1
unescape(String string) : String
Returns a URI-decoded version of a string.
| String | string | URI-encoded string to be decoded. |
- Remarks
- unescape has been phased out in favor of decodeURIComponent.
- See Also
- Availability
JavaScript 1.0 | JScript 1.0
