Java Reference
In-Depth Information
It's possible to create multi-dimensional arrays of three, four, or even a hundred dimensions, but things
can start to get very confusing, and you'll fi nd that you rarely, if ever, need more than two dimensions.
To give you an idea, here's how to declare and access a fi ve-dimensional array:
var myArray = new Array();
myArray[0] = new Array();
myArray[0][0] = new Array();
myArray[0][0][0] = new Array();
myArray[0][0][0][0] = new Array();
myArray[0][0][0][0][0] = “This is getting out of hand”
document.write(myArray[0][0][0][0][0]);
That's it for arrays for now, but you'll return to them in Chapter 4, where you'll fi nd out something
shocking about them. You'll also learn about some of their more advanced features.
Summary
In this chapter you have built up knowledge of the fundamentals of JavaScript's data types and vari-
ables and how to use them in operations. In particular, you saw that
JavaScript supports a number of types of data, such as numbers, text, and Booleans.
Text is represented by strings of characters and is surrounded by quotes. You must match the
quotes surrounding strings. Escape characters enable you to include characters in your string
that cannot be typed.
Variables are JavaScript's means of storing data, such as numbers and text, in memory so that
they can be used again and again in your code.
Variable names must not include certain illegal characters, like the percent sign (
% ) and the
ampersand ( & ), or be a reserved word, like with .
Before you can give a value to a variable, you must declare its existence to the JavaScript
interpreter.
JavaScript has the four basic math operators, represented by the symbols plus (
+ ), minus ( - ),
star ( * ), and forward slash ( / ). To assign values of a calculation to a variable, you use the equals
sign ( = ), termed the assignment operator.
Operators have different levels of precedence, so multiplication and division will be calculated
before addition and subtraction.
Strings can be joined, or concatenated, to produce one big string by means of the
+ operator.
When numbers and strings are concatenated with the + operator, JavaScript automatically con-
verts the number into a string.
Although JavaScript's automatic data conversion suits us most of the time, there are occasions
when you need to force the conversion of data. You saw how parseInt() and parseFloat()
can be used to convert strings to numbers. Attempting to convert strings that won't convert will
result in NaN (Not a Number) being returned.
Arrays are a special type of variable that can hold more than one piece of data. The data are
inserted and accessed by means of a unique index number.
Search WWH ::




Custom Search