![](https://csdnimg.cn/release/download_crawler_static/5953043/bg1.jpg)
![](https://csdnimg.cn/release/download_crawler_static/5953043/bg2.jpg)
![](https://csdnimg.cn/release/download_crawler_static/5953043/bg3.jpg)
THE
MISSING
MANUAL
®
JavaScript
David Sawyer McFarland
Beijing • Cambridge • Farnham • Köln • Sebastopol • Tokyo
Do wn lo ad f ro m Wo w! e Bo ok < ww w. wo we bo ok .c om >
![](https://csdnimg.cn/release/download_crawler_static/5953043/bg4.jpg)
JavaScript: The Missing Manual
by David Sawyer McFarland
Copyright © 2008 David Sawyer McFarland. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are
also available for most titles (safari.oreilly.com). For more information, contact our corporate/institutional
sales department: (800) 998-9938 or corporate@oreilly.com.
Printing History:
July 2008: First Edition.
Nutshell Handbook, the Nutshell Handbook logo, the O’Reilly logo, and “The book that should have been
in the box” are registered trademarks of O’Reilly Media, Inc. JavaScript: The Missing Manual, The Missing
Manual logo, Pogue Press, and the Pogue Press logo are trademarks of O’Reilly Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and O’Reilly Media, Inc. was aware of a
trademark claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and author assume no
responsibility for errors or omissions, or for damages resulting from the use of the information contained
herein.
ISBN: 978-0-596-51589-8
[LSI] [2011-05-12]
![](https://csdnimg.cn/release/download_crawler_static/5953043/bg5.jpg)
iii
Table of Contents
The Missing Credits ................................................................................... xi
Introduction................................................................................................. 1
Part One: Getting Started with JavaScript
Chapter 1: Writing Your First JavaScript Program ................................ 19
Introducing Programming ...................................................................................................................... 19
What’s a Computer Program? .......................................................................................................... 21
How to Add JavaScript to a Page ........................................................................................................... 22
External JavaScript Files .................................................................................................................... 24
Your First JavaScript Program ................................................................................................................ 26
Writing Text on a Web Page ................................................................................................................... 29
Attaching an External JavaScript File ..................................................................................................... 29
Tracking Down Errors .............................................................................................................................. 32
The Firefox JavaScript Console ........................................................................................................ 34
Displaying the Internet Explorer Error Dialog Box ........................................................................ 35
Accessing the Safari Error Console ................................................................................................. 36
Chapter 2: The Grammar of JavaScript................................................... 39
Statements ................................................................................................................................................ 39
Commands ................................................................................................................................................ 40
Types of Data ............................................................................................................................................ 40
Numbers ............................................................................................................................................. 41
Strings .................................................................................................................................................. 41
Booleans ............................................................................................................................................. 42