In JScript, you can declare a variable and concurrently declare its type using type annotation. In the following example, the variable count is declared to be of type int (integer). Since no initial value is provided, count has the default value of int, which is 0 (zero). You do not need to use typed variables, but programs that use untyped variables are slower and more prone to errors. var count : int; // An integer variable. You can also assign an initial value to a variable: var count : int = 1; // An initialized integer variable. Constants, which are declared in much the same way as variables, must be initialized. Once a constant value is defined, its value cannot be changed. For example: const daysInWeek : int = 7; // An integer constant. const favoriteDay : String = "Friday"; // A string constant. const maxDaysInMonth : int = 31, maxMonthsInYear : int = 12 Note: Declaring variables without the var keyword generates a compile-time error when running in fast mode, the default mode for JScript .NET. To compile a program from the command line that does not use the var keyword, you must turn off the fast option by using /fast-. It is not safe to turn off the fast option in ASP.NET because of threading issues.

JScript .NET provides many data types to use in your programs. These types can be divided into two main categories, value data types and reference data types (also referred to as JScript objects). To add types to JScript, you can import namespaces or packages that contain new data types, or you can define new classes that can be used as new data types.

The following table shows the value data types supported by JScript. The second column describes the equivalent Microsoft .NET Framework data type. You can declare a variable of the .NET Framework type or the JScript value type and achieve exactly the same results. The storage size (where applicable) and range are also given for each type. The third column lists the amount of storage required for one instance of a given type, if applicable. The fourth column provides the range of values that can be stored by a given type.

JScript value type .NET Framework type Storage size Range
boolean System.Boolean N/A true or false
char System.Char 2 bytes Any Unicode character
float
(single-precision floating-point)
System.Single 4 bytes Approximate range is -1038 to 1038 with accuracy of about 7 digits. Can represent numbers as small as 10-44
Number, double
(double-precision floating-point)
System.Double 8 bytes Approximate range is -10308 to 10308 with accuracy of about 15 digits. Can represent numbers as small as 10-323
decimal System.Decimal 12 bytes (integral part) Approximate range is -1028 to 1028 with accuracy of 28 digits. Can represent numbers as small as 10-28
byte
(unsigned)
System.Byte 1 byte 0 to 255
ushort
(unsigned short integer)
System.UInt16 2 bytes 0 to 65,535
uint
(unsigned integer)
System.UInt32 4 bytes 0 to 4,294,967,295
ulong
(unsigned extended integer)
System.UInt64 8 bytes 0 to approximately 1020
sbyte
(signed)
System.SByte 1 byte -128 to 127
short
(signed short integer)
System.Int16 2 bytes -32,768 to 32,767
int
(signed integer)
System.Int32 4 bytes -2,147,483,648 to 2,147,483,647
long
(signed extended integer)
System.Int64 8 bytes Approximately -1019 to 1019
void N/A N/A Used as the return type for a function that does not return a value.

The next table shows the reference data types (JScript objects) that JScript provides and that can be used as types. Reference types do not have a pre-defined specific storage size.

JScript reference type .NET Framework type Refers to
ActiveXObject No direct equivalent An Automation object.
Array Interoperates with System.Array and typed arrays Arrays of any type.
Boolean Interoperates with System.Boolean A Boolean value, either true or false.
Date Interoperates with System.DateTime Dates are implemented using the JScript Date object. The range is approximately 285,616 years on either side of January 1, 1970.
Enumerator No direct equivalent An enumeration of items in a collection. For backwards compatibility only.
Error No direct equivalent An Error object.
Function No direct equivalent A Function object.
Number Interoperates with System.Double A numeric value with an approximate range of -10308 to 10308 and with an accuracy of about 15 digits. Can represent numbers as small as 10-323.
Object Interoperates with System.Object An Object reference.
RegExp Interoperates with System.Text.RegularExpression.Regex Class A regular expression object.
String Data Type
(variable-length)
System.String 0 to approximately 2 billion Unicode characters. Each character is 16 bits (two bytes).
String Object
(variable-length)
Interopertates with System.String 0 to approximately 2 billion Unicode characters. Each character is 16 bits (two bytes).
VBArray No direct equivalent A read-only Visual Basic array. For backwards compatibility only.
// Simple array of strings; initially empty. The variable 'names' itself // will be null until something is assigned to it var names : String[]; // Create an array of 50 objects; the variable 'things' won't be null, // but each element of the array will be until they are assigned values. var things : Object[] = new Object[50]; // Put the current date and time in element 42. things[42] = new Date(); // An array of arrays of integers; initially it is null. var matrix : int[][]; // Initialize the array of arrays. matrix = new (int[])[5]; // Initialize each array in the array of arrays. for(var i = 0; i<5; i++) matrix[i] = new int[5]; // Put some values into the matrix. matrix[2][3] = 6; matrix[2][4] = 7; // A three-dimensional array var multidim : double[,,] = new double[5,4,3]; // Put some values into the matirx. multidim[1,3,0] = Math.PI*5.;