Advantages of Modules
- The code can be separated into multiple files and reusability is improved
- Modules can be reused in multiple other applications or modules
- Modules are like packages in java which we can avoid namespace issues
- All variables or functions defined in the module are private the same module
There are two types of modules can be defined in ECMAScript 2015
- Default Module-Default modules are modules which contain only one per module
- Named Modules -The modules contain multiple modules in a file
Import and Export Default ModuleIn this single module is declared for export functionality. Modules need to be declared with an export keyword to make use of it in another part of the code. Import keyword is used to import the modules Here is a syntax for import and export Default module declaration.
Once the module is exported, It is ready to use in other modules using import keyword. Here is a syntax for import keyword
export default ModuleName // Export is declared with export keyword
import ModuleName from 'filepath without extension'