Preface

In the preface to the first edition of this book, I talked about the ubiquity of JavaScript and its exponential growth. This shows no signs of slowing down as the second edition is published. In fact, there is a new phenomenon known as “JavaScript fatigue” that is used to describe the unrelenting barrage of new JavaScript tools and methodologies that are constantly appearing. In my view, this shouldn’t be viewed as a negative, it’s just a sign that the JavaScript landscape is a fertile one, and that will mean an ever-expanding list of new tools and libraries. Most of these help to take the language forward and make it better, and eventually these ideas make it into the official language. There’s now a new version of JavaScript scheduled for release every year. And, with each passing year, and each new version, the language becomes more powerful and mature, capable of building complex applications. It’s still not perfect, but it’s getting better all the time.

While I was halfway through writing this second edition, I read somewhere that print books about JavaScript programming are pointless because they are out of date by the time they are published. On the one hand, I can appreciate this. The first edition of this book didn't use ES6 notation, which seemed to be a good idea at the time as it had only just become a standard, and hardly any browsers supported it. But ES6 quickly gained traction due to Node.js, and tools such as Babel bypassed the need for browser support. This meant that some of the code in the first edition appeared dated almost immediately after it was published. In this edition, I tried to avoid this happening by using the most up-to-date notation of the language, and removing most of the references to browser support. And, on the other hand, it doesn't matter, because, despite the unrelenting pace the JavaScript world moves at, the basic principles of programming don't change. This book is as much about learning to program as it is about learning JavaScript and, as in the first edition, it will teach you about fundamental programming principles. The way they are implemented might change, but the basic theory remains the same. I feel that JavaScript is an excellent choice of language for learning these techniques, particularly because of how easy it is to access – you can run a program from within your browser, without the need for installing any special software!

It’s an exciting time to be programming JavaScript, and it’s never too late to learn. In fact, if you are only just beginning to learn, you are lucky, as you’ll be able to ignore all its baggage from the past and focus on the exciting language it has become. Whatever level you’re at, I hope you get something from this book and enjoy programming in the language of the web!

The aim of this book is to introduce you to programming using the JavaScript language, eventually helping you to develop into a JavaScript ninja.

This is an exciting time to be learning JavaScript, having finally outgrown its early reputation as a basic scripting language used to produce cringeworthy effects on web pages. Today, JavaScript is used to produce professional and powerful web applications. Modern browsers are now capable of running JavaScript code at lightning speed, and Node.js has helped to revolutionize it by facilitating its use in other environments. This has led to a much more professional and structured approach to building JavaScript applications, where it is now considered a fully-fledged programming language. In short, JavaScript has grown up.

JavaScript has a number of cool features that make it stand out from other languages, such as callbacks, first-class functions, prototypal inheritance, and closures. Its event-based model also makes it a very good choice for modern web application development. JavaScript’s ace in the pack, though, is something of which every language is envious ― its *ubiquity*. JavaScript is available almost everywhere; anybody who has access to a browser can use it. And this is increasing every year as it becomes more readily available outside the browser environment. This translates into JavaScript’s reach being immense: it is already the [most popular language on GitHub I can only see JavaScript growing even more popular in the future as it becomes the language of choice for the Internet of Things — helping to control household appliances, and even program robots.

Before I get carried away, though, I should point out that JavaScript is far from perfect. It is missing some important programming constructs, such as modules and private functions, which are considered standard in many modern programming languages. Yet it’s also an unbelievably flexible language, where many of these gaps can be filled using the tools that it provides. In addition, many libraries have sprung into existence that help to extend JavaScript so that it’s now able to reach its full potential.

This book starts off with the basics, assuming no programming or JavaScript knowledge, but quickly gets up to speed covering all the main topics in great depth, such as functions, objects, and DOM manipulation.

More advanced topics, such as error handling and testing, functional programming and OOP, are then introduced after the basics have been covered. There have been some exciting new developments in the world of JavaScript over the last few years, such as Ajax, HTML5 APIs and task runners, and these are covered in the last part of the book. There’s also a practical project to build a quiz application that is developed throughout the book towards the end of each chapter. I’ve written with developing for modern browsers in mind, so I’ve always tried to use the most up-to-date methods in the examples. Having said that, I’ve also tried to acknowledge if something might not work in an older browser, or if a workaround is needed.

It’s a long way ahead ― 16 chapters, to be precise. But remember, every ninja’s journey starts with a single page (or something like that, anyway). So, turn the page and let’s get started!

Who Should Read This Book

This book is suitable for beginner-level web designers and developers. Some knowledge of HTML and CSS is assumed, but no previous programming experience is necessary.

Conventions Used

You’ll notice that we’ve used certain typographic and layout styles throughout this book to signify different types of information. Look out for the following items.

Code Samples

Code in this book is displayed using a fixed-width font, like so:

<h1>A Perfect Summer's Day</h1>
<p>It was a lovely day for a walk in the park. The birds were singing and the kids were all back at school.</p>
            

Some lines of code should be entered on one line, but we’ve had to wrap them because of page constraints. An ➥ indicates a line break that exists for formatting purposes only, and should be ignored:

URL.open("http://www.sitepoint.com/responsive-web-design-real-user-testing/?responsive1");
            
            

Tips, Notes, and Warnings

Hey, You!

Tips provide helpful little pointers.

Ahem, Excuse Me ...

Notes are useful asides that are related—but not critical—to the topic at hand. Think of them as extra tidbits of information.

Make Sure You Always ...

... pay attention to these important points.

Watch Out!

Warnings highlight any gotchas that are likely to trip you up along the way.

Supplementary Materials

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

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