ES Modules import and export
📖 Scenario: You are building a small Node.js project that uses ES Modules to organize code. You want to split your code into two files: one for utility functions and one for the main program.
🎯 Goal: Create a module file that exports a function, then import and use that function in the main file using ES Modules syntax.
📋 What You'll Learn
Create a file
utils.js that exports a function called greetThe
greet function takes a name parameter and returns a greeting stringCreate a file
main.js that imports the greet function from utils.jsCall the
greet function in main.js with the argument 'Alice'💡 Why This Matters
🌍 Real World
Organizing code into modules helps keep projects clean and reusable. ES Modules are the standard way to share code in modern JavaScript and Node.js.
💼 Career
Understanding ES Modules is essential for JavaScript developers working on scalable applications, libraries, or any code that benefits from modular design.
Progress0 / 4 steps