PREFACE

JAVASCRIPT IS THE MOST POPULAR programming language in the world. It is used on all major Internet sites, and even those not so important. Whether you make a purchase from an online retailer, manage your funds using your bank's website, visit a news site to get caught up on current events, or simply read a blog written by one of the millions of bloggers worldwide, you have experienced JavaScript in some way.

Despite this popularity, there has always been some form of confusion regarding JavaScript. Some claim, because of its name, that it's a light version of Java, a programming language originally developed by Sun and now owned by Oracle. This is not the case at all. While JavaScript's syntax is similar to Java's, JavaScript is its own language used primarily to program the web pages you visit daily using a web browser. Its purpose is to provide interactivity for the user — making the web page or web application feel like a conventional application running on your computer.

JavaScript is a simple, yet complex, object-oriented language. While getting started with JavaScript takes little time, it can take years to master the language. And even then, masters of the language still find themselves learning something new about it.

This book aims to teach you JavaScript, to put you on the right path so that you can use the language to add interactivity to your web pages and applications. Don't worry if you don't know how to program. This book teaches you JavaScript from the very beginning — showing you the concepts behind the basics of all programming languages. You'll find that JavaScript can be a gateway to the world of programming. It was for your author.

WHOM THIS BOOK IS FOR

This book is for beginners at two levels: those who have never used JavaScript before, and those who have, but did not learn the language outside of a library such as jQuery.

To get the most out of this book you'll need an understanding of HTML and CSS, and how to use these two technologies to create web pages. JavaScript lives inside the web browser, and it's used to interact with a web page loaded into the browser. So being able to write HTML and style it with CSS is an important skill to have before you learn JavaScript.

WHAT THIS BOOK COVERS

JavaScript 24-Hour Trainer teaches you how to use JavaScript in your web pages from the absolute beginning: adding JavaScript to your page. From there the book moves on to introduce you to the fundamentals of JavaScript (and every programming language for that matter), such as syntax, variables, functions, decisions, and loops. From there you'll be introduced to object-oriented programming by looking at some of JavaScript's built-in objects, and you'll learn to write your own objects to represent complex data.

Building on that base, you'll learn how to use JavaScript to program the browser by creating and manipulating new windows and scripting frames. Then you'll learn how to interact with the HTML elements in a page by adding them, removing them, and modifying their styles. You'll learn how to react to a user's action by using events, and the different ways to do this for different browsers. You'll continue a study of the browser and page by learning how to animate elements, script HTML forms, and leverage Ajax to send and receive data from the server.

You'll then turn your studies toward errors, debugging, and best practices. You'll learn how to identify and avoid common mistakes, as well as how to handle errors that are caused by stimuli outside your control. For those tough-to-find errors, you'll learn how to debug your code with Firebug. After that you'll learn some conventions that professional JavaScript developers follow, as well as techniques for writing efficient and maintainable JavaScript.

HOW THIS BOOK IS STRUCTURED

This book consists of short lessons, each focusing on a particular aspect of the JavaScript language. It is not meant as an exhaustive resource or as an in-depth look at technical aspects of the language. The goal is to teach you what you need to know in order to start using JavaScript in your web pages and applications.

This book consists of 43 lessons. Most are reasonably short — much shorter than chapters in most other books. A couple of them are longer, but that is only because the content of that particular lesson warrants the bigger size.

The lessons are broken into three distinct sections:

  • Part I: Introduction to JavaScript: This section teaches you the fundamentals of the JavaScript language. You can also apply the concepts in this section to just about any other programming language.

  • Part II: Programming the Browser: The primary use of JavaScript is to manipulate the browser and the web page loaded into it. You'll learn how to use the language to do that.

  • Part III: Handling Errors, Debugging, and Best Practices: Errors happen, and some can be avoided. You'll learn how to spot errors, deal with errors you can't control, and locate hard-to-find bugs with debugging and Firebug. You also learn techniques employed by professional developers that you can use to make your code more efficient and maintainable.

Most lessons contain a tutorial called "Try It," and each tutorial applies the concepts of the lesson in an example. You can also watch the DVD to see your author complete the tutorial, as well as offer commentary on the subject matter.

After you've finished reading the book and watching the DVD, you can visit Wrox's p2p forums, where your author offers support.

INSTRUCTIONAL VIDEOS ON DVD

Not everyone can learn straight from a book; kudos to those of you who can. For the rest of us (including your author), a visual and audible aid is often required. This is exactly why a DVD accompanies this book. Most of the book's lessons have a corresponding video tutorial, complete with commentary. So if seeing something done and hearing it explained help you understand a subject better than just reading about it, this book-and-DVD combination is just the thing for you.

CONVENTIONS

To help you get the most from the text and keep track of what's happening, this book uses a number of conventions.

Warning

Boxes like this one hold important, not-to-be forgotten information that is directly relevant to the surrounding text.

Note

Notes, tips, hints, tricks, and asides to the current discussion are offset and placed in italics like this.

Note

References like this one point you to the DVD to watch the instructional video that accompanies a given lesson.

As for styles in the text:

  • New terms and important words are italicized when introduced.

  • Code appearing in text looks like this: document.body.

  • URLs look like the following when inside text: www.wrox.com.

  • Code blocks are presented in the following way:

    A monofont type on its own line(s)
    denotes code examples.

SUPPORTING PACKAGES AND CODE

As you work through the lessons in this book, you can choose to type the code and create all the files manually or you can use the supporting code files that accompany the book. All the code and other support files used in this book are available for download at www.wrox.com. On the site, simply locate the book's title (either by using the Search box or by using one of the title lists), and then click the Download Code link on the book's detail page to obtain all the source code for the book.

Note

Because many books have similar titles, you may find it easiest to search by ISBN; this book's ISBN is 978-0-470-64783-7.

Once you download the code, just decompress it with your favorite compression tool. Alternatively, you can go to the main Wrox code download page at www.wrox.com/dynamic/books/download.aspx to see the code available for this book and all other Wrox books.

ERRATA

Every effort is made to ensure that there are no errors in the text or in the code. However, no one is perfect, and mistakes do occur. If you find an error in this book or any Wrox book for that matter, such as a spelling mistake or faulty piece of code, your feedback is appreciated. By sending in errata, you can save a reader hours of frustration, and at the same time, you can help your author and Wrox provide even higher-quality information.

To find the errata page for this book, go to www.wrox.com and locate the title using the Search box or one of the title lists. Then, on the Book Search Results page, click the Errata link. On this page, you can view all errata that have been submitted for this book and posted by Wrox editors.

Note

A complete book list, including links to errata, is also available at www.wrox.com/misc-pages/booklist.shtml.

If you don't spot "your" error on the Errata page, click the Errata Form link and complete the form to send us the error you have found. We'll check the information and, if appropriate, post a message to the book's errata page and fix the problem in subsequent editions of the book.

P2P.WROX.COM

For author and peer discussion, join the P2P forums at p2p.wrox.com. The forums are a web-based system you can use to post messages relating to Wrox books and related technologies and interact with other readers and technology users. The forums offer a subscription feature to e-mail you topics of interest of your choosing when new posts are made to the forums. Wrox authors and editors, other industry experts, and your fellow readers are present on these forums.

At http://p2p.wrox.com you will find a number of different forums that will help you not only as you read this book, but also as you develop your own applications. To join the forums just follow these steps:

  1. Go to p2p.wrox.com and click the Register link.

  2. Read the terms of use and click Agree.

  3. Complete the required information for joining as well as any optional information you wish to provide and click Submit.

  4. You will receive an e-mail with information describing how to verify your account and complete the joining process.

    Note

    You can read messages in the forums without joining P2P, but in order to post your own messages you must join.

Once you join you can post new messages and respond to messages other users post. You can read messages at any time on the Web. If you would like to have new messages from a particular forum e-mailed to you, click the Subscribe to This Forum icon by the forum name in the forum listing.

For more information about how to use the Wrox P2P, be sure to read the P2P FAQs for answers to questions about how the forum software works as well as many common questions specific to P2P and Wrox books. To read the FAQs, click the FAQ link on any P2P page.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.202.61