Preface
On the surface, JavaScript is a simple programming language that lets you make changes to your web pages on the fly, while they’re being displayed in a web browser. How hard could that be to learn, right? It sounds like something you could knock over in an afternoon.
But JavaScript is bigger on the inside than it seems from the outside. If you were a Dr. Who fan, you might call it the Tardis of programming languages. If you’re not a Dr. Who fan, roll your eyes with me as the fanboys (and girls) geek out. Everyone back with me? Put your Daleks away, Jimmy. As I was saying, JavaScript sounds like it should be simple. Nevertheless, throughout its ten year history (so far), the best ways of doing things with JavaScript have seemed to change with the seasons. And advice on how to write good JavaScript can be found everywhere: “Do it this way—it’ll run faster!” “Use this code—it’ll run on more browsers!” “Stay away from that feature—it causes memory leaks!” Too many other JavaScript books—some of them from very respected names in the industry—will teach you a handful of simple solutions to simple problems and then call it a day, leaving you with just enough rope with which to hang yourself when you actually try to solve a real-world problem on your own. And when in desperation you go looking on the Web for an example that does what you need it to, you’ll likely be unable to make sense of the JavaScript code you find, because the book you bought didn’t cover many of the truly useful features of the language, such as object literals, event listeners, or closures.
This book aims to be different. From the very first page, we’ll show you the right way to use JavaScript. By working through fully fleshed-out examples that are ready to be plugged right into a professionally-designed web site, you’ll gain the confidence not only to write JavaScript code of your own, but to understand code that was written by others, and even to spot harmful, old-fashioned code that's more trouble than it’s worth!
Who Should Read this Book?
Whether you’ve never seen a line of JavaScript code in your life, or you’ve seen one too many lines that doesn’t do what you expect, this book will show you how to make JavaScript work for you. We assume going in that you’ve got a good handle on web design with HyperText Markup Language (HTML) and Cascading Style Sheets (CSS). You needn’t be an expert in these languages, but as we’ll see, JavaScript is just another piece in the puzzle. The better you understand basic web design techniques, the more you can enhance them with JavaScript.