ECMAScript 2015 has introduced built-in modules. The features of modules are as follows:
- Each module is defined in its own file.
- Functions or variables defined in a module are not visible outside unless you explicitly export them.
- You can place the export keyword in front of any variable, function, or class declaration to export it from the module.
- You can use the import keyword to consume the exported variable, function, or class declaration.
- Modules are singletons. Only a single instance of a module exists, even if it was imported multiple times.
Some exporting possibilities are listed here:
// export dataexport let color: string = "red";// export functionexport function sum(num1: number, num2: number) { return num1 + num1;