JScript  

Type Conversion

[This is preliminary documentation and subject to change]

Convert one type to another.

typename(expression)

Arguments

typename

Required. Must be a valid type. Valid types for JScript include Boolean, Number, String, int, long, float, double, Object, Date, Array, or Function, but additional types can be introduced into JScript either by importing a namespace that contains a new type, or by declaring user-defined types as classes.

expression

Required. Any valid expression.

Remarks

If a conversion cannot be performed, a TypeError exception occurs. For example, the string "1234" can be successfully converted to an integer, but converting from two distinct types of objects may not be allowed.

Example

The following example attempts to explicitly convert a string into an integer, and then convert the integer into a Boolean. Both old and new style syntax is shown:

// Old-style JScript – Note all variables are Objects.
var sVal1 = "42";
var iVal1 = Number(sVal1);
var bVal1 = Boolean(iVal1);

// New-style JScript – Note all variables are of the declared type.
var sVal2 : String = "42";
var iVal2 : int = int(sVal2);
var bVal2 : Boolean = Boolean(iVal2);

Requirements

Version 7

See Also

Array Object | Boolean Data Type | Date Object | double Data Type | float Data Type | Function Object | int Data Type | long Data Type | Number Object | Object Object | String Object