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 a...