|
JScript provides automatic type conversion as the context may require. This means that if the context expects a value to be a string, for example, JScript tries to convert the value to a string.
The language has six types of data. All values have one of these types:
· Undefined. The undefined type has one value only, undefined.
· Null. The null type has one value only, null.
· Boolean. The Boolean type represents the two logical values, true and false.
· String. A string delineated by single or double quotation marks; can contain zero or more unicode characters. An empty string ("") has zero characters and length.
· Number. Can be an integer or floating point number according to the IEEE 754 specification. There also several special values:
· NaN, or not a Number
· Positive infinity
· Negative infinity
· Positive zero
· Negative zero
· Object. An object definition including its set of properties and methods.
The following table defines what happens when the context requires that JScript convert one data type into another:
Output |
Input | |||||
|
Undefined |
Null |
Boolean |
Number |
String |
Object |
Boolean |
false |
false |
no conversion |
false if +0, -0 or NaN, otherwise true |
false if empty string (""), otherwise true |
true |
Number |
NaN |
NaN |
1 if true +0 if false |
no conversion |
If it cannot be interpreted as a number, it is interpreted as NaN |
Number object |
String |
undefined |
"null" |
"true" or "false" |
The absolute value of the number plus its sign, with the following exceptions:
|
no conversion |
String object |
Object |
runtime error |
runtime error |
New Boolean object |
New Number object |
New String object |
no conversion |
Copyright 2002 Sun Microsystems, Inc. All rights reserved. Legal Notice.