JS AdvancedLesson 45Free preview
JS Modules
This lesson is part of JavaScript · All levels
Summary
The modules allow JavaScript code to be broken into several files so that it is more organized and easy to test. Exports are done by export, either named export or default export, and then reused by import in another file. To run it in the browser, the script tag must be given the type='module' attribute that also automatically enables strict mode.
Key points
- Export const / export function for named export, export default for main export
- Import {name} from './file.js' import named export
- Import default module may be given a free name when importing
- The module script must be loaded with type='module' and path often requires.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.