tag is deprecated in HTML 4.0, since style sheets can provide the same capability. Document Object Model (DOM) The set of objects that JavaScript can use to refer to the browser window and portions of the HTML document. The W3C (World Wide Web Consortium) DOM is a standardized version supported by the latest browsers, and allows access to every object within a Web page. Dynamic HTML (DHTML) The combination of HTML, JavaScript, CSS, and the DOM, which allows dynamic Web pages to be created. DHTML is not a W3C standard or a version of HTML. element A single member of an array, referred to with an index. In the DOM, an element is a single node defined by an HTML tag. event A condition, often the result of a user’s action, that can be detected by a script. event handler A JavaScript statement or function that will be executed when an event occurs. expression A combination of variables, constants, and operators that can be evaluated to a single value. feature sensing A scripting technique that detects whether a feature, such as a DOM method, is supported before using it to avoid browser incompatibilities. function A group of JavaScript statements that can be referred to using a function name and arguments.
Glossary
375
global variable A variable that is available to all JavaScript code in a Web page. It is declared (first used) outside any function. Hypertext Markup Language (HTML) The language used in Web documents. JavaScript statements are not HTML, but can be included within an HTML document. increment To increase the value of a variable by one. In JavaScript, this is done with the increment operator, ++. interpreter The browser component that interprets JavaScript statements and acts on them. Java An object-oriented language developed by Sun Microsystems. Java applets can be embedded within a Web page. JavaScript has similar syntax, but is not the same as Java. JavaScript A scripting language for Web documents, loosely based on Java’s syntax, developed by Netscape. JavaScript is now supported by the most popular browsers. layer An area of a Web page that can be positioned and can overlap other sections in defined ways. Layers are also known as positionable elements. local variable A variable that is available to only one function. It is declared (first used) within the function. loop A set of JavaScript statements that are executed a number of times, or until a certain condition is met. method A specialized type of function that can be stored in an object, and acts on the object’s properties. Navigator A browser developed by Netscape, and the first to support JavaScript. node In the DOM, an individual container or element within a Web document. Each HTML tag defines a node. object A type of variable that can store multiple values, called properties, and functions, called methods. operator A character used to divide variables or constants used in an expression. parameter A variable sent to a function when it is called, also known as an argument. property A variable that is stored as part of an object. Each object can have any number of properties. rule In CSS, an individual element of a style block that specifies the style for an HTML tag, class, or identifier.
C
376
Appendix C
scope The part of a JavaScript program that a variable was declared in and is available to. selector In a CSS rule, the first portion of the rule that specifies the HTML tag, class, or identifier that the rule will affect. statement A single line of a script or program. string A group of text characters that can be stored in a variable. tag In HTML, an individual element within a Web document. HTML tags are contained within angle brackets, as in and . text node In the DOM, a node that stores a text value rather than an HTML element. Nodes that contain text, such as paragraphs, have a text node as a child node. variable A container, referred to with a name, that can store a number, a string, or an object. VBScript A scripting language developed by Microsoft, with syntax based on Visual Basic. VBScript is supported only by Microsoft Internet Explorer. World Wide Web Consortium (W3C) An international organization that develops and maintains the standards for HTML, CSS, and other key Web technologies. XHTML (Extensible Hypertext Markup Language) A new version of HTML developed by the W3C. XHTML is similar to HTML, but conforms to the XML specification. XML (Extensible Markup Language) A generic language developed by the W3C (World Wide Web Consortium) that allows the creation of standardized HTML-like languages, using a DTD (Document Type Definition) to specify tags and attributes.
APPENDIX
D
JavaScript Quick Reference This appendix is a quick reference for the JavaScript language. It includes the built-in objects and the objects in the basic object hierarchy, JavaScript statements, and built-in functions.
Built-in Objects The following objects are built in to JavaScript. Some can be used to create objects of your own; others can only be used as they are. Each is detailed below.
Array You can create a new array object to define an array—a numbered list of variables. (Unlike other variables, arrays must be declared.) Use the new keyword to define an array, as in this example: students = new Array(30)
378
Appendix D
Items in the array are indexed beginning with 0. Refer to items in the array with brackets: fifth = students[4];
Arrays have a single property, length, which gives the current number of elements in the array. They have the following methods: •
join quickly joins all of the array’s elements together, resulting in a string. The elements are separated by commas, or by the separator you specify.
•
reverse
•
returns a sorted version of the array. Normally this is an alphabetical sort; however, you can use a custom sort method by specifying a comparison routine.
returns a reversed version of the array.
sort
String Any string of characters in JavaScript is a string object. The following statement assigns a variable to a string value: text = “This is a test.”
Since strings are objects, you can also create a new string with the new keyword: text = new String(“This is a test.”);
String objects have a single property, length, which reflects the current length of the string. There are a variety of methods available to work with strings: •
substring
•
toUpperCase
•
toLowerCase
•
indexOf
•
lastIndexOf
returns a portion of the string. converts all characters in the string to uppercase. converts all characters in the string to lowercase.
finds an occurrence of a string within the string. finds an occurrence of a string within the string, starting at the end of
the string. creates an HTML link using the string’s text.
•
link
•
anchor
creates an HTML anchor within the current page.
There are also a few methods that allow you to change a string’s appearance when it appears in an HTML document: •
string.big
•
string.blink
•
string.bold
displays big text, using the tag in HTML 3.0. displays blinking text, using the