4 Primer, part 2

 

This chapter covers

  • Understanding and using JavaScript functions
  • Using the JavaScript concise function syntax
  • Defining and using JavaScript arrays
  • Creating objects using the literal syntax
  • Using classes to create objects
  • Defining and using JavaScript modules

In this chapter, I continue to describe the basic features of TypeScript and JavaScript that are required for Angular development.

4.1 Preparing for this chapter

This chapter uses the Primer project created in chapter 3. No changes are required for this chapter. Open a new command prompt, navigate to the Primer folder, and run the command shown in listing 4.1 to start the Angular development tools.

Tip

You can download the example project for this chapter—and for all the other chapters in this book—from https://github.com/manningbooks/pro-angular-16. See chapter 1 for how to get help if you have problems running the examples.

Listing 4.1. Starting the development tools
ng serve --open

After an initial build process, the Angular tools will open a browser window and display the content shown in figure 4.1.

Figure 4.1. Running the example application

This chapter continues to use the browser’s JavaScript console. Press F12 to open the browser’s developer tools and switch to the console; you will see the following results (you may have to reload the browser):

Result 1: 100.00
Result 2: 100.00

4.2 Defining and using functions

4.2.1 Defining optional function parameters

4.2.2 Defining default parameter values

4.2.3 Defining rest parameters

4.2.4 Defining functions that return results

4.2.5 Using functions as arguments to other functions

4.3 Working with arrays

4.3.1 Reading and modifying the contents of an array

4.3.2 Enumerating the contents of an array

4.3.3 Using the spread operator

4.3.4 Using the built-in array methods

4.4 Working with objects

4.4.1 Understanding literal object types

4.4.2 Defining classes

4.4.3 Checking object types

4.5 Working with JavaScript modules

4.5.1 Creating and using modules

4.6 Summary

sitemap