Chapter XXII · Modules
import
The `import` statement brings exported functions, objects, or variables from another module into the current file scope.
01 How It Works
Think of ordering required specialized parts delivered straight to your workbench station.
Import statements are statically analyzed and hoisted during compilation, loading dependencies before execution.
example.js
import { add, subtract } from './math.js';
console.log(add(5, 3));
1. Specify desired exported identifiers inside curly braces `{}`.
2. Provide the relative file path source string.
3. Use imported members immediately.
02 Practical Example
Here is how you might see this concept applied in real-world code:
practical.js
import defaultUser, { getUserData } from './api.js';
Key Takeaway
Use `import` to bring code dependencies safely into your active module file.