- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript Module Scripts
JavaScript Modules
JavaScript Module Scripts
A script becomes a module by adding
type="module"to its tag.
Without it, import and export are syntax errors.
The attribute also changes a few things about how the script loads.
Example
Example
javascript
// Demonstrating the behaviour a module script gives you,
// without needing a real module file.
console.log("this simulates a deferred module script");A module script behaves like a normal deferred script, described below.
What type="module" Changes
It enables import and export.
The script is deferred automatically, without needing the defer attribute.
It always runs in strict mode.
