- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript Modules
JavaScript Modules
JavaScript Modules
A module is a file that can export values for other files to import.
Before modules, every script shared one global scope, and names easily collided.
A module has its own scope; nothing is visible outside it unless exported.
Example
Example
javascript
// The examples below simulate two files with a plain object,
// since import/export only works between real separate files.
const mathUtils = {
double(n) {
return n * 2;
}
};
console.log(mathUtils.double(5));