The module
is a new feature in Ecmascript 6th edition (ES6). When you arrow the attribute type="module"
to an archive .js
, you turn it into a módulo
.
A module is a normal JS file, but with some peculiarities:
- The code of a module automatically wins
"use strict";
, even if you don’t define it in him;
- You can use the methods
import
and export
in modules to exchange objects such as function
, class
, var
, let
, or const
.
Everything that is declared inside a module, by default, is local to the module. If you want something declared in a module to be public, so that other modules can use it, you must export this feature (export
), and for another module to use it, you must import it (import
).
As to compatibility, the MDN shows the following table:
On the same page you are informed:
This Feature is only just Beginning to be implemented in browsers
natively at this time. It is implemented in Many transpilers, such as
Typescript and Babel, and bundlers such as Rollup, Webpack and Parcel.
Free translation:
This feature is just starting to be implemented natively
in the browsers at this time. It is implemented in several
transpilators, like Typescript and Babel, and groupings like Rollup,
Webpack and Parcel.