JavaScript and TypeScript: Part 1
In this chapter I provide a quick tour of the most important basic features of the JavaScript language as they apply to Angular development. I don’t have the space to describe JavaScript completely, so I have focused on the essentials that you’ll need to
- PDF / 332,849 Bytes
- 23 Pages / 504 x 720 pts Page_size
- 22 Downloads / 211 Views
JavaScript and TypeScript: Part 1 In this chapter I provide a quick tour of the most important basic features of the JavaScript language as they apply to Angular development. I don’t have the space to describe JavaScript completely, so I have focused on the essentials that you’ll need to get up to speed and follow the examples in this book. In Chapter 6, I describe some of the more advanced JavaScript features that you will need and some of the additional features provided by TypeScript. The JavaScript language is managed through a standard process that defines new features. Modern browsers have started to implement features from the ECMAScript 6 (also known as ES6) standard, and ECMAScript 7 (ES7) is making its way into service as I write this. The new standards broaden the features available to JavaScript developers and make using JavaScript more consistent with more conventional languages such as C# or Java. Modern browsers update themselves, which means that a Google Chrome user, for example, is likely to have a recent release of the browser that implements at least some of the most recent JavaScript features. Sadly, older browsers that don’t update themselves are still in widespread use, which means you can’t rely on modern features being available for use in your application. There are two ways to approach this problem. The first is to use only the core JavaScript features that you can rely on being present in the browsers that your application targets. The second is to use a compiler that processes your JavaScript files and converts them into code that can run on older browsers. It is the second approach that Angular takes and that I describe in this chapter. Table 5-1 summarizes this chapter. Table 5-1. Chapter Summary
Problem
Solution
Listing
Create JavaScript functionality
Use JavaScript statements
5
Create groups of statements that are executed on command
Use functions
6, 7, 10–12
Define functions that can handle more or fewer arguments than parameters
Use default or rest parameters
8, 9
Express functions more concisely
Use arrow functions
13
Store values and objects for later use
Declare variables using the let or var keyword
14–16
Store basic data values
Use the JavaScript primitive types
17–20
Control the flow of JavaScript code
Use conditional statements
21
Determine whether two objects or values are the same
Use the quality and identity operators
22–23
Explicitly convert types
Use the to methods
24–26
Store related objects or values together in sequence
Use an array
27–33
© Adam Freeman 2018 A. Freeman, Pro Angular 6, https://doi.org/10.1007/978-1-4842-3649-9_5
63
Chapter 5 ■ JavaScript and TypeScript: Part 1
USING “PLAIN” JAVASCRIPT FOR ANGULAR When Angular 2 was introduced, the use of TypeScript was optional, and it was possible to write Angular applications using plain JavaScript. The result was awkward and required some contorted code to recreate the effect of key TypeScript features, but it was possible, and Google provided a complete set of API documents
Data Loading...