Chapter 9

Here are the solutions to the Exercises for the Chapter 9, Using Modules chapter.

Exercise 1

  1. false. Each module is loaded at most once in the execution flow.

  2. false. No; to export as default, we need to place the keyword default. Inlined export creates a named export.

  3. false. The importing module provides names for the defaults, so there are no conflicts.

  4. true. Inline exports are less verbose than explicit exports.

  5. false. A module may have at most one default export, but it may have any number of nondefault exports.

Exercise 2

Use explicit import when you want to export

  1. only select variables from multiple declarations

  2. a variable with a different name than its declared name

Exercise 3

The importing module sees the name of the default exported item as default, but the importing module may assign whatever name it likes for that item.

Exercise 4

The module that has the code

 export * from 'some-module';

will reexport all exports, except the default export, from the module named some-module. The module that imports the exporting module will be able to see all the exported items (except default) from some-module without a direct import to some-module.

Exercise 5

Let’s pick a name, deliver, for the default item exported by fasttrack and give a namespace fasttrack for housing the items exported by the module fasttrack. Here’s the code to import that module:

 import deliver, * as fasttrack from 'fasttrack';
..................Content has been hidden....................

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