JavaScript Modules
Before ES6 (ECMAScript 2015), JavaScript had no native way to organize code into modules. Developers had to rely on multiple <script> tags or community formats like CommonJS. Today, ES6 Modules let us easily separate and share code across files.
Named Exports
You can export multiple variables or functions from a single file by placing the export keyword in front of them. When you import them, you must use their exact names enclosed in curly braces {}.
Default Exports
If a file acts as a primary component—like a React class or a specific utility object—it's best to use a default export. A file can only have one default export, and it can be imported without curly braces.
Browser Implementation
To use ES6 modules natively in an HTML file without a bundler (like Webpack or Vite), you must specify the type="module" attribute on your script tag: <script type="module" src="app.js"></script>. This automatically enforces strict mode and defers execution.
View Full Transcript+
This section contains the full detailed transcript of the video lessons for accessibility purposes and quick review. It covers the necessity of splitting JS files as applications scale, the strict syntax of named vs default exports, wildcard imports using the asterisk (*), and aliasing imports with the 'as' keyword to prevent naming collisions in local scopes.
