- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript import
JavaScript Modules
JavaScript import
importbrings an exported value from another module into the current file.
The syntax mirrors export closely.
What you import must match what the other file actually exported.
Example
Example
javascript
// Standing in for a module already imported elsewhere.
const mathModule = {
double: function (n) { return n * 2; },
PI_ROUNDED: 3
};
const { double, PI_ROUNDED } = mathModule;
console.log(double(5));
console.log(PI_ROUNDED);