Sams Teach Yourself JavaScript in 24 Hours
- Table of Contents
- Copyright
- About the Author
- Acknowledgments
- We Want to Hear from You!
- Reader Services
- Introduction
- Part I: Getting Started
- Hour 1. Understanding JavaScript
- Hour 2. Creating a Simple Script
- Hour 3. How JavaScript Programs Work
- Part II: Learning JavaScript Basics
- Hour 4. Using Functions and Variables
- Hour 5. Using Strings and Arrays
- Hour 6. Testing and Comparing Values
- Hour 7. Repeating Yourself: Using Loops
- Hour 8. Using Math and Date Functions
- Part III: The Document Object Model (DOM)
- Hour 9. Working with the Document Object Model
- Hour 10. Responding to Events
- Hour 11. Using Windows and Frames
- Hour 12. Getting Data with Forms
- Hour 13. Using Graphics and Animation
- Part IV: Moving on to Advanced JavaScript Features
- Hour 14. Creating Cross-Browser Scripts
- Hour 15. Creating Custom Objects
- Hour 16. Working with Sounds and Plug-Ins
- Hour 17. Debugging JavaScript Applications
- Part V: Working with Dynamic HTML (DHTML)
- Hour 18. Working with Style Sheets
- Hour 19. Using Dynamic HTML (DHTML)
- Hour 20. Using Advanced DOM Features
- Part VI: Putting It All Together
- Hour 21. Improving a Web Page with JavaScript
- Hour 22. Creating a JavaScript Game
- Hour 23. Creating DHTML Applications
- Hour 24. JavaScript Tips and Tricks
- Part VII: Appendices
- Appendix A. Other JavaScript Resources
- Appendix B. Tools for JavaScript Developers
- Appendix C. Glossary
- Appendix D. JavaScript Quick Reference
- Appendix E. DOM Quick Reference
Understanding Objects
In Hour 2, you learned that variables are containers that can store a number, a string of text, or another value. JavaScript also supports objects. Like variables, objects can store data —but they can store two or more pieces of data at once.
The items of data stored in an object are called the properties of the object. As an example, you could use objects to store information about people as in an address book. The properties of each person object might include a name, address, and telephone number.
JavaScript uses periods to separate object names and property names. For example, for a person object called Bob, the properties might include Bob.address and Bob.phone.
Objects can also include methods. These are functions that work with the object's data. For example, our person object for the address book might include a display() method to display the person's information. In JavaScript terminology, the statement Bob.display() would display Bob's details.
Don't worry if this sounds confusing—you'll be exploring objects in much more detail later in this book. For now, you just need to know the basics. JavaScript supports three kinds of objects:
- Built-in objects are objects built into the JavaScript language. You've already encountered one of these, Date, in Hour 2, "Creating a Simple Script." Other built-in objects include Array and String, which you'll explore in Hour 5, "Using Strings and Arrays," and Math, which is explained in Hour 8, "Using Math and Date Functions."
- Browser objects are objects that represent various components of the browser and the current HTML document. For example, the alert() function you used earlier in this chapter is actually a method of the window object. You'll explore these in more detail in Hour 9, "Working with the Document Object Model."
- Cust om objects are objects you create yourself. For example, you could create a person object, as in the examples in this section. You'll learn to use custom objects in Hour 15, "Creating Custom Objects."
Handling Events | Next Section

Account Sign In
View your cart