JavaScript’s nature can be summarized as follows:
bind(), built-in map() and reduce() for arrays, etc.) and object-oriented programming (mutable state, objects, inheritance, etc.).
On one hand, JavaScript has several quirks and missing features (for example, it has no block-scoped variables, no built-in modules, and no support for subclassing). Therefore, where you learn language features in other languages, you learn patterns and workarounds in JavaScript. On the other hand, JavaScript includes unorthodox features (such as prototypal inheritance and object properties). These, too, have to be learned, but are more a feature than a bug.
Note that JavaScript engines have become quite smart and fix some of the quirks, under the hood. For example:
But JavaScript also has many elegant parts. Brendan Eich’s favorites are:[1]
The last two items, object literals and array literals, let you start with objects and introduce abstractions (such as constructors, JavaScript’s analog to classes) later. They also enable JSON (see Chapter 22).
Note that the elegant parts help you work around the quirks. For example, they allow you to implement block scoping, modules, and inheritance APIs—all within the language.
JavaScript was influenced by several programming languages (as shown in Figure 3-1):
Date constructor (which is a port of java.util.Date).
function comes from AWK.
onclick.