Assumptions and Approach

As stated earlier, this book assumes you have experience with (X)HTML and CSS, as well as a general understanding of how web applications work. Programming experience isn’t necessary, but the book covers all aspects of JavaScript, some of which are relatively sophisticated. Though the heavier pieces are few, you will need to understand JavaScript enough to work with the newer Ajax libraries.

The book is broken into four sections:

Chapters 1 through 3 provide an introduction to the structure of a JavaScript application, including the simple data types supported in the language, as well as the basic statements and control structures. These establish a baseline of understanding of the language for the sections that follow.

Chapters 4 through 8 introduce the main JavaScript objects, including the all-important function, script access for web-page forms, event handling, scripting security, and working with cookies. Combined, these topics comprise the core of JavaScript, and with these chapters, you can validate form elements, set and retrieve cookies, capture and provide functionality for events, and even create JavaScript libraries. The functionality covered in these chapters has been basic to JavaScript for 10 years, and will remain so for at least another 10.

Chapters 9 through 11 delve into the more sophisticated aspects of web-page development. These chapters cover the Browser Object Model and the newer Document Object Model, and show how you can create your own custom objects. Understanding these models is essential if you wish to create new windows, or individually access, modify, or even dynamically create any page element. In addition, with custom objects, you can then move beyond the capabilities that are prebuilt into either language or browser.

Chapters 12 through 14 get into the advanced uses of JavaScript, including DHTML, Ajax, and some of the many wonderful new libraries that support both.

Chapter 1, Introduction and First Looks

Introduces JavaScript and provides a quick first look at a small web-page application. This chapter also covers some issues associated with the use of JavaScript, including the many tools that are available, as well as issues of security and accessibility.

Chapter 2, JavaScript Data Types and Variables

Provides an overview of the basic data types in JavaScript, as well as an overview of language variables, identifiers, and the structure of a JavaScript statement.

Chapter 3, Operators and Statements

Covers the basic statements of JavaScript, including assignment, conditional, and control statements, as well as the operators necessary for all three.

Chapter 4, The JavaScript Objects

Introduces the first of the built-in JavaScript objects, including Number, String, Boolean, Date, and Math. The chapter also introduces the RegExp object, which provides the facilities to do regular-expression pattern matching. Regular expressions are essential when checking form fields.

Chapter 5, Functions

Focuses on one other JavaScript built-in object, the function. The function is key to creating custom objects, as well as packaging blocks of JavaScript into pieces that can be used, again and again, in many different JavaScript applications. This JavaScript function is relatively simple, but certain aspects can be complex. These include recursion and closure, both of which are introduced in this chapter and detailed in Chapter 11.

Chapter 6, Catching Events

Focuses on event handling, including both the original form of event handling (which is still commonly used in many applications), as well as the newer DOM-based event handling.

Chapter 7, Forms and JiT Validation

Introduces using JavaScript with forms and form fields, including how to access each field type—such as text input fields and drop-down lists—and validate the data once retrieved. Form validation before the form is submitted to the web server helps prevent an unnecessary round trip to the server, and thus saves both time and resource use.

Chapter 8, The Sandbox and Beyond: Cookies, Connectivity, and Piracy

Covers script-based cookies, which store small pieces of data on the client’s machine. With cookies, you can store usernames, passwords, and other information so that users don’t have to keep reentering data. In addition, since discussion of cookies inevitably leads to discussions of security, the section also covers some security issues associated with JavaScript.

Chapter 9, The Basic Browser Objects

Begins to look at object models accessible from JavaScript, starting with the Browser Object Model—a hierarchy of objects including the window, document, forms, history, location, and so on. Through the BOM, JavaScript can open windows; access page elements such as forms, links, and images; and even do some basic dynamic effects.

Chapter 10, DOM: The Document Object Model

Focuses on the Document Object Model, a straightforward, but not trivial, object model that provides access to all document elements and attributes. You’ll see documents that are based in XML (such as XHTML) as well as HTML. Though the model is comprehensive and its coverage is fairly straightforward, there could be some challenging moments in the chapter for new programmers.

Chapter 11, Creating Custom JavaScript Objects

Demonstrates how to create custom objects in JavaScript and covers the entire prototype structure that enables such structures in the language. Some programming language concepts are discussed, such as inheritance and encapsulation, but you don’t need experience with these concepts.

Chapter 12, Building Dynamic Web Pages: Adding Style to Your Script

Provides a general introduction to some of the more commonly used Dynamic HTML effects, including drag and drop, collapsing and expand page sections, visibility, and movement. Some understanding of CSS is required.

Chapter 13, Moving Outside the Page with Ajax

Introduces Ajax, which, despite all the excitement it has generated, is actually not a complicated use of JavaScript. In addition to covering the components of Ajax, the chapter also provides one example of an application that has promoted Ajax probably more than any other: Google Maps.

Chapter 14, Good News: Juicy Libraries! Amazing Web Services! Fun APIs!

Covers some of the more popular libraries you can download and use for free. This includes Prototype, Sabre’s Rico, Dojo, MochiKit, Yahoo! UI, and Between these libraries and the book, you’ll have all you need to create incredible, and useful, web applications.

Get Learning JavaScript now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.