Data Type Conversion
Language Reference |
Microsoft 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:The following table defines what happens when the context requires that JScript convert one data type into another:
- The undefined type has one value only, undefined.
- The null type has one value only, null.
- The Boolean type represents the two logical values, true and false.
- Strings, delineated by single or double quotation marks, contain zero or more unicode characters. An empty string ("") has zero characters and length.
- Numbers can be integers or floating point numbers according to the IEEE 754 specification. There also several special values:
- NaN, or not a Number
- Positive Infinity
- Negative Infinity
- Positive zero
- Negative zero
- An Object type is an object definition including its set of properties and methods.
Output Data Type Input Data Type 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:
NaN returns "NaN" +0 or -0 returns "0" + infinity returns "Infinity" - infinity returns "-Infinity" no conversion String object object runtime error runtime error New Boolean object New Number object New String object no conversion