1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6+ < title > Modules in JS</ title >
7+ </ head >
8+ < body >
9+ < script >
10+ /*
11+ # Modules in JS:
12+ - Collection of code related to specific functionality
13+ - Benefits:
14+ - Improves readability and maintainability
15+ - Avoids redundancy (Using DRY principle)
16+ - Achieve encapsulation
17+ - Syntax:
18+ <script src="user.js" type="module">
19+ - Import/Export:
20+ - Export: An internal entity sent ouside
21+ - Import: An external entity brough inside
22+ - Types of exports/imports:
23+ - Default export/import ('default' keyword)
24+ - Can only export a single entity
25+ - Syntax:
26+ - Export: export default func1
27+ - Import: import func1 from './relative-path'
28+ - Rename entity during import
29+ - import test from './relative-path'
30+ - Named export/import
31+ - Can export multiple entities
32+ - Syntax:
33+ - Export
34+ - Way 1: export { funct1, funct2 }
35+ - Way 2: Export during declaration
36+ export function func1() {}
37+ export function func2() {}
38+ - Import: import { funct1, funct2 } from './relative-path'
39+ - Rename entity during import ('as' keyword)
40+ - Syntax:
41+ import {
42+ funct1 as abc,
43+ funct2 as def
44+ } from './relative-path'
45+ - Relative path:
46+ - ../ Parent folder
47+ - ./ Current folder
48+ - / Child folder
49+ */
50+ </ script >
51+ < script src ="index.js " type ="module "> </ script >
52+ < script src ="user.js " type ="module "> </ script >
53+ < script src ="product.js " type ="module "> </ script >
54+ < script src ="cart.js " type ="module "> </ script >
55+ < script src ="order.js " type ="module "> </ script >
56+ < script src ="feature/abc.js " type ="module "> </ script >
57+ </ body >
58+ </ html >
0 commit comments