Preface

Learning a programming language requires getting acquainted with its syntax, the set of forms and structures that make up legal programs, and semantics, the meaning or behavior of those forms. But beyond that, mastering a language requires understanding its pragmatics, the ways in which the language’s features are used to build effective programs. This latter category can be especially subtle, particularly in a language as flexible and expressive as JavaScript.

This book is concerned with the pragmatics of JavaScript. It is not an introductory book; I assume you have some familiarity with JavaScript in particular and programming in general. There are many excellent introductory books on JavaScript, such as Douglas Crockford’s JavaScript: The Good Parts and Marijn Haverbeke’s Eloquent JavaScript. My goal with this book is to help you deepen your understanding of how to use JavaScript effectively to build more predictable, reliable, and maintainable JavaScript applications and libraries.

JavaScript versus ECMAScript

It’s helpful to clarify some terminology before diving into the material of this book. This book is about a language almost universally known as JavaScript. Yet the official standard that defines the specification describes a language it calls ECMAScript. The history is convoluted, but it boils down to a matter of copyright: For legal reasons, the standards organization, Ecma International, was unable to use the name “JavaScript” for its standard. (Adding insult to injury, the standards organization changed its name from the original ECMA—an abbreviation for European Computer Manufacturers Association—to Ecma International, without capitalization. By the time of the change, the capitalized name ECMAScript was set in stone.)

Formally, when people refer to ECMAScript they are usually referring to the “ideal” language specified by the Ecma standard. Meanwhile, the name JavaScript could mean anything from the language as it exists in actual practice, to one vendor’s specific JavaScript engine. In common usage, people often use the two terms interchangeably. For the sake of clarity and consistency, in this book I will only use ECMAScript to talk about the official standard; otherwise, I will refer to the language as JavaScript. I also use the common abbreviation ES5 to refer to the fifth edition of the ECMAScript standard.

On the Web

It’s hard to talk about JavaScript without talking about the web. To date, JavaScript is the only programming language with built-in support in all major web browsers for client-side application scripting. Moreover, in recent years, JavaScript has become a popular language for implementing server-side applications with the advent of the Node.js platform.

Nevertheless, this is a book about JavaScript, not about web programming. At times, it’s helpful to talk about web-related examples and applications of concepts. But the focus of this book is on the language—its syntax, semantics, and pragmatics—rather than on the APIs and technologies of the web platform.

A Note on Concurrency

A curious aspect of JavaScript is that its behavior in concurrent settings is completely unspecified. Up to and including the fifth edition, the ECMAScript standard says nothing about the behavior of JavaScript programs in an interactive or concurrent environment. Chapter 7 deals with concurrency and so technically describes unofficial features of JavaScript. But in practice, all major JavaScript engines share a common model of concurrency. And working with concurrent and interactive programs is a central unifying concept of JavaScript programming, despite its absence from the standard. In fact, future editions of the ECMAScript standard may officially formalize these shared aspects of the JavaScript concurrency model.