- Integers - Can be expressed in decimal, octal, or hexadecimal form. When led by a 0x with characters from 0-9, and a-f, the value is hexadecimal such as "0x24". The equivalent octal value is 044 and decimal is 36.
- Floating point - Examples are 3.14, -3.14, 314e-2
- Boolean values (true or false).
- String values - May be enclosed by single ' or double " quotes. The \' or \"sequence of characters will insert a quote character into a string.
- Arrays of any of the above types.
There is also a NULL value which can be any of the types above, exclusive of arrays and objects. the type if the variable is determined at its creation time, by the type of variable assigned to it. Therefore the example:
creates an integer variable. If the variable value is later changed to:
It becomes a string. Note here that when the variable is created, the keyword "var" is used to create it. When referencing the variable, after its creation, or changing its value, the keyword "var" is not used.
When evaluating expressions, variable types are favored in the following order:
- Floating point
Type Conversion Functions
They must be declared before use with a statement like Name = new Array(length) or Name = new Array().
Tree = new Array(4);
Tree = "Roots"
Tree = "Trunk"
Tree = "Branches"
Tree = "Leaves"
The same array can also be declared at the same time values are assigned as follows:
Tree = new Array('Roots', 'Trunk', 'Branches', 'Leaves')
As new elements are added to arrays, they are automatically expanded. For instance the line:
Tree = "Twigs"
Will make the array be 6 elements long. The values in the array can be of mixed types for instance it is legal to do the following:
Tree = 1
Arrays may be nested as follows:
Tree = new Array('Roots', new Array('Trunk', 'Branches', 'Leaves'))
The following line:
will print "Leaves".
- length - Example: Tree.length