🔰module
JS ⟩ module
Modules provide structure to bigger programs by separating the code into pieces with clear interfaces and dependencies.
- interface: the part that’s visible from other modules. 
- dependencies: other modules that it makes use of. 
in Node.js, each JS file is treated as a module.
in a module there's no "module scope object" for these top-level declarations to be added to as property.
( 👉 compare: global var / function is global object property❗️)
- other features of modules 
- other related topics - module pattern - used before introduction of native ES module. 
 
- VSCode ⟩ - can not use import statement outside a module (YouTube) rename file extension to - .mjs
- Unexpected token on "export default const" - // ⛔ SyntaxError: export default const a = { ... } // ^^^^^ <---- Unexpected token 'const' // ✅ syntax is OK now! const a = { ... }; export default a;
 
Last updated
Was this helpful?