INTRODUCTION - Wrox Press Beginning JavaScript 5th (2015)

Wrox Press Beginning JavaScript 5th (2015)

INTRODUCTION

JAVASCRIPT IS A SCRIPTING LANGUAGE that enables you to enhance static web applications by providing dynamic, personalized, and interactive content. This improves the experience of visitors to your site and makes it more likely that they will visit again. You must have seen the flashy drop-down menus, moving text, and changing content that are now widespread on websites—they are enabled through JavaScript. Supported by all the major browsers, JavaScript is the language of choice on the web. It can even be used outside web applications—to automate administrative tasks, for example.

This book aims to teach you all you need to know to start experimenting with JavaScript: what it is, how it works, and what you can do with it. Starting from the basic syntax, you’ll move on to learn how to create powerful web applications. Don’t worry if you’ve never programmed before—this book will teach you all you need to know, step by step. You’ll find that JavaScript can be a great introduction to the world of programming: with the knowledge and understanding that you’ll gain from this book, you’ll be able to move on to learn newer and more advanced technologies in the world of computing.

WHO THIS BOOK IS FOR

To get the most out of this book, you’ll need to have an understanding of HTML, CSS, and how to create a static web page. You don’t need to have any programming experience.

This book will also suit you if you have some programming experience already and would like to turn your hand to web programming. You will know a fair amount about computing concepts, but maybe not as much about web technologies.

Alternatively, you may have a design background and know relatively little about the web and computing concepts. For you, JavaScript will be a cheap and relatively easy introduction to the world of programming and web application development.

Whoever you are, I hope that this book lives up to your expectations.

WHAT THIS BOOK COVERS

You’ll begin by looking at exactly what JavaScript is, and taking your first steps with the underlying language and syntax. You’ll learn all the fundamental programming concepts, including data and data types, and structuring your code to make decisions in your programs or to loop over the same piece of code many times.

Once you’re comfortable with the basics, you’ll move on to one of the key ideas in JavaScript—the object. You’ll learn how to take advantage of the objects that are native to the JavaScript language, such as functions, dates, and strings, and find out how these objects enable you to manage complex data and simplify your programs. Next, you’ll see how you can use JavaScript to manipulate and detect objects made available to you in the browser and detect the browsers.

From here, you’ll move on to more advanced topics, such as writing code to dynamically manipulate elements within a web page and executing code when certain things happen within your page. You’ll also learn how to script forms and other controls. Using this knowledge, you can start to create truly professional-looking applications that enable you to interact with the user.

You’ll then learn how to store data within the browser and communicate directly with a server. You’ll also learn how to write code for the new HTML5 media elements, and write your own custom user interface for them.

You’ll explore some of the time saving JavaScript frameworks such as jQuery, Modernizr, Prototype, and MooTools and see how they work and how they can help you create sophisticated JavaScript powered applications.

Finally, you’ll look at common syntax and logical errors, how you can spot them, and how to use the JavaScript debuggers for Chrome, Internet Explorer, Firefox, Safari, and Opera to aid you with this task. Also, you need to examine how to handle the errors that slip through the net, and ensure that these do not detract from the experience of the end user of your application.

All the new concepts introduced in this book will be illustrated with practical examples, which enable you to experiment with JavaScript and build on the theory that you have just learned.

You’ll find four appendixes at the end of the book. Appendix A provides solutions to the exercises included at the end of most chapters throughout the book. The remaining appendixes contain the reference material that your authors hope you find useful and informational. Appendix B contains the JavaScript language’s core reference. Appendix C contains a complete W3C DOM Core reference—as well as information on the HTML DOM and DOM level 2 Event model. Appendix D contains the decimal and hexadecimal character codes for the Latin-1 character set.

WHAT YOU NEED TO USE THIS BOOK

Because JavaScript is a text-based technology, all you really need to create documents containing JavaScript is a text editor. Any will do.

Also, in order to try out the code in this book, you will need a web browser that supports a modern version of JavaScript. Ideally, this means the latest versions of Chrome, Internet Explorer, Firefox, Safari, and Opera. The book has been extensively tested with these browsers. However, the code should work in any modern web browser. Where there are exceptions, they will be clearly noted.

CONVENTIONS

To help you get the most from the text and keep track of what’s happening, we’ve used a number of conventions throughout the book.

TRY IT OUT

The Try It Out is an exercise you should work through, following the text in the book.

1. It usually consists of a set of steps.

2. Each step has a number.

3. Follow the steps with your copy of the database.

As you work through each Try It Out, the code you’ve typed will be explained in detail.

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

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

As for styles in the text:

· We highlight in italic type new terms and important words when we introduce them.

· We show keyboard strokes like this: Ctrl+A.

· We show file names, URLs, and code within the text like so:

persistence.properties.

· We present code in two different ways:

Important code in code examples is highlighted with a gray background.

The gray highlighting is not used for code that’s less important in the present context, or that has been shown before.