The first time you know that JavaScript has a module concept is usually introduced using <script> tags, but only on HTML files
The added module is like the Include in PHP, require can use the introduced content,
However, PHP is the default introduction of the file inside all available, and JavaScript is to choose to export, select Import, can only use the introduced functions, variables, objects
Understanding the JavaScript Module section on Codecademy
modules in JavaScript are reusable pieces of code that can be exported from one program and imported into another program.
module.exports
Use the module export for other programs.
- module.export = variable; | | Module.export = {Object Inside Property method}
require()
Imports the modules used in the current program.
- Conste variable = require (' introduced file relative address with suffix. js ');
ES6 introduces a more flexible, simpler syntax for exporting modules:
- The default export is used to
export default
exports JavaScript objects, functions, and raw data types.
- named exports use
export
keyword to export the data in the variable.
- Export {variable name, object name, function};
- named exports can be used
as
keyword aliases .
- Export {variable name as Alias, object name, function};
import
is a keyword that imports any object, function, or data type.
- Import variable from ' File relative address (no file suffix) ';
JavaScript module Import and Export