- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript export
JavaScript Modules
JavaScript export
exportmakes a function, variable or class available to other modules.
There are two kinds: named exports and a single default export.
A file can have many named exports but only one default.
Example
Example
javascript
// Simulating a module's exports as a plain object.
const mathModuleExports = {
double: function (n) { return n * 2; },
PI_ROUNDED: 3
};
console.log(mathModuleExports.double(5));
console.log(mathModuleExports.PI_ROUNDED);