Introduction to Part 1

This part deals with the fundamentals of JavaScript, whatever the environment in which it is hosted. Most of the time, JavaScript is associated with a browser, but it is a language by itself. We use the term “Core JavaScript” or “ECMAScript” to mean what is “pure JavaScipt”, in contrast with what is added by the environment into which JavaScript is embedded.

There is no need to be a JavaScript expert, good applications can be quickly programmed, provided that you adopt some “good practices”. Coding without good practice (aka. “anti-pattern”) may seem correct while being silently error prone, with errors difficult to spot. That is why you will find “Recommendations” paragraphs throughout the chapters, suggesting ways to encode “patterns”. ES5 and ES6 standards facilitate this type of coding.

Part 1 can be used as a manual: going directly to the section that concerns one immediate problem, or instead studying a chapter more in depth, for instance with the sensitive issues of the language (e.g. prototypes, closures). Here is a quick tour of the features of this amazing language:

– Variables: declaration, definition, types (ban every “var”):

Here, we insist on the subtle distinction between the status of “declared” and “defined” variables, which deserves a particular attention. In this chapter, the creation of the tree structure of “variable scopes”, the implicit “hoisting” and the (dangerous) implicit declaration of global variables are presented. The ES6 version provides new declaration keywords, which can avoid many (silent) causes of error.

– Controls: booleans, tests and loops (replace “for” loops by array methods):

JavaScript looks classically procedural, when it comes to controlling the status of variables. But several operators may react surprisingly, due to their “polymorphism”: they do not react in the same way according to the type (e.g. number or string) and implicit (silent) recasting can be done. We emphasize such traps, and suggestions are provided to avoid them.

– Data: characters used as numbers, and strings and dates:

An appropriate format is required to represent quantitative (numbers) or qualitative data (names, texts, dates). Any unicode character can be used, and figures can be used within numbers or names or dates: we detail some issues related to type conversions and value comparisons, which are among the tricky points.

– Objects (restrict “new” to built-in or APIs objects):

The construction of specific objects is required to structure linked data into meaningful information and to assign it the appropriate methods. The objects in JavaScript are treated rather differently than in most object-oriented languages. We focus on the innovations of ES6 that provide better tools to build objects in the “prototype” way.

– Arrays (get rid of loops “for”):

To handle time series or relational data, tables and matrices are required. We detail the most useful methods, added to the JavaScript Array object since ES5 or ES6, that make it possible to avoid the loops, rewriting them in a “functional” code style.

– Functions (do program functionally, as often as possible):

Functions are “first-class objects” in JavaScript. This is probably the most important part of this language, and the key reasons for its efficiency and longevity.

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

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