For Marka true friend, and fellow creator.
Preface
Even though this is my second book on technologies in the JavaScript ecosystem, I still find myself somewhat surprised at my role as a JavaScript expert and evangelist. Like so many programmers, I held a strong prejudice against JavaScript up until about 2012. To do such an about-face still feels a little disorienting.
My prejudice was for the usual reasons: I considered JavaScript a toy language (without really learning it properly, and therefore not knowing of what I spoke) that was practiced by dangerous, sloppy, untrained amateur programmers. There is a little truth in both of these reasons. ES6 was developed quickly, and even its inventor Brendan Eich admits there are things that he didnt get right the first time aroundand by the time he realized it, too many people were relying on the problematic behavior for him to effectively change it (show me the language that doesnt suffer from this problem, however). As for the second reason, JavaScript did make programming suddenly accessible. Not only did everyone have a browser, but with only a little effort, they could see the JavaScript that enabled the websites that were rapidly proliferating on the Web. People learned by trial and error, by reading each others code andin so many casesemulating poorly written code with insufficient understanding.
Im glad I have learned enough about JavaScript to recognize thatfar from being a toy languageit is based on extremely solid foundations, and is powerful, flexible, and expressive. Im also glad I have come to embrace the accessibility that JavaScript brings. I certainly hold no animosity toward amateurs: everyone has to start somewhere, programming is a profitable skill, and a career in programming has many advantages.
To the new programmer, the amateur, I say this: there is no shame in being an amateur. There is some shame in staying an amateur (if you make programming your profession, certainly). If you want to practice programming, practice it. Learn everything you can, from every source you can. Keep an open mind andperhaps most importantlyquestion everything. Question every expert. Question every experienced programmer. Constantly ask Why?
For the most part, I have tried to keep this book to the facts of JavaScript, but it is impossible to completely avoid opinion. Where I offer opinions, take them for what they are. You are welcome to disagree, and you are encouraged to seek out the opinions of other experienced developers.
You are learning JavaScript at a very exciting time. The Web is leaving its infancy (technically speaking), and web development isnt the confusing, complicated Wild West that it was 5 and 10 years ago. Standards like HTML5 and ES6 are making it easier to learn web development, and easier to develop high-quality applications. Node.js is extending the reach of JavaScript beyond the browser, and now it is a viable choice for system scripting, desktop application development, backend web development, and even embedded applications. Certainly I havent had this much fun programming since I started in the mid-1980s.
A Brief History of JavaScript
JavaScript was developed by Brendan Eich, a developer at Netscape Communications Corporation, in 1995. Its initial development was very rapid, and much of the criticism leveled at JavaScript has cited the lack of planning foresight during its development. However, Brendan Eich was not a dabbler: he had a solid foundation in computer science, and incorporated remarkably sophisticated and prescient ideas into JavaScript. In many ways, it was ahead of its time, and it took 15 years for mainstream developers to catch on to the sophistication the language offered.
In November 1996, Netscape announced that they had submitted JavaScript to Ecma, a private, international nonprofit standards organization that carries significant influence in the technology and communications industries. Ecma International published the first edition of the ECMA-26 specification, which was, in essence, JavaScript.
The relationship between Ecmas specificationswhich specify a language called ECMAScriptand JavaScript is mostly academic. Technically, JavaScript is an implementation of ECMAScript, but for practical purposes, JavaScript and ECMAScript can be thought of interchangeably.
The last major ECMAScript version was 5.1 (generically referred to as ES5), published in June 2011. Browsers in the wild that are old enough not to support ECMAScript 5.1 have fallen well below the single digits, and its safe to say that ECMAScript 5.1 is the current lingua franca of the Web.
ECMAScript 6 (ES6)which is the focus of this bookwas published by Ecma International in June 2015. The working name for the specification prior to publication was Harmony, and you will hear ES6 referred to as Harmony, ES6 Harmony, ES6, ES2015, and ECMAScript 2015. In this book, we will refer to it simply as ES6.
ES6
If ES5 is the current lingua franca of the Web, the attentive reader might be wondering why this book focuses on ES6.
ES6 represents a significant advancement in the JavaScript language, and some of ES5s major shortcomings are addressed in ES6. I think you will find that ES6 is generally a much more pleasant and powerful language to work with (and ES5 was quite enjoyable to start with). Alsothanks to transcompilersyou can write ES6 today and transcompile it to web-compatible ES5.
With ES6 finally published, browser support for it will grow steadily, and at some point, transcompilation will no longer be necessary to reach a broad audience (I am not foolish enough to make a predictioneven a rough oneabout when that will happen).