HTML and CSS Reference
In-Depth Information
9
JavaScript
Core Objects
9.1 What Are Core Objects?
Like an apple, JavaScript has a core, and at its core are objects. Everything you do in
JavaScript will be based on objects; you may create your own as we did in Chapter 8,
“Objects,” or use JavaScript's core objects. Core objects are built right into the language.
JavaScript provides built-in objects that deal with the date and time, math, strings, reg-
ular expressions, numbers, and other useful entities. The good news is that the core
objects are consistent across different implementations and platforms and were stan-
dardized by the ECMAScript 1.0 specification, allowing programs to be portable.
Although each object has a set of properties and methods that further define it, this topic
does not detail every one, but highlights those that will be used most often. For a com-
plete list of properties and objects, go to http://www.echoecho.com/jsquickref.htm .
9.2 Array Objects
An array is a collection of like values—called elements —such as an array of colors,
an array of strings, or an array of images. Each element of the array is accessed with an
index value enclosed in square brackets (see Figure 9.1). An index is also called a sub-
script. There are two types of index values: a nonnegative integer and a string. Arrays
indexed by numbers are called numeric arrays and arrays indexed by strings are called
associative arrays (see Figure 9.2). In JavaScript, arrays are built-in objects with some
added functionality.
“red”
“blue”
“green”
“yellow”
color[0]
color[1]
color[2]
color[3]
Figure 9.1 A numeric Array object called color. Index values are numbers.
213
 
 
 
 
Search WWH ::




Custom Search