module
is new feature in ECMAScript 6th edition (ES6). When you set the type="module"
attribute to a .js
file, you convert it to módulo
.
A module is a normal JS file, but with some quirks:
- The code in a module automatically gains
"use strict";
, even if you do not define it in it;
- You can use the
import
and export
methods in the modules to swap 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
).
For compatibility, MDN shows the next table :
On the same page you are informed:
This feature is only 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 only beginning to be implemented natively
in browsers right now. It is implemented in several
such as TypeScript and Babel, and groupers such as Rollup,
Webpack and Parcel.