Here are the solutions to the Exercises for the Chapter 9, Using Modules chapter.
false. Each module is loaded at most once in the execution flow.
false. No; to export as default, we need to place the keyword default. Inlined export creates a named export.
false. The importing module provides names for the defaults, so there are no conflicts.
true. Inline exports are less verbose than explicit exports.
false. A module may have at most one default export, but it may have any number of nondefault exports.
Use explicit import when you want to export
only select variables from multiple declarations
a variable with a different name than its declared name
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.
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.
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'; |