Modules — import/export & What to Learn Next
ES6 modules split code into files with explicit import and export. React, Vue, and modern Node.js all use this system. This is the last core ES6+ topic before you teach Node or React.
Named exports
// utils/math.js
export function add(a, b) { return a + b; }
export const TAX_RATE = 0.18;
// checkout.js
import { add, TAX_RATE } from './utils/math.js';
const total = add(100, 100 * TAX_RATE);
Default export
// services/api.js
export default async function fetchCourses() {
const res = await fetch('/api/courses');
return res.json();
}
// app.js
import fetchCourses from './services/api.js';
Re-export & import all
import * as MathUtils from './utils/math.js';
MathUtils.add(2, 3);
🌍 Real-world example — Split LMS helpers into modules
// format.js
export function formatPrice(inr) {
return `₹${inr.toLocaleString('en-IN')}`;
}
// catalog.js
import { formatPrice } from './format.js';
export function showEbook(ebook) {
return `${ebook.title} — ${formatPrice(ebook.price)}`;
}Bonus — modern syntax you will see
// Optional chaining — safe deep access
const city = user?.address?.city;
// Nullish coalescing — default only for null/undefined
const theme = settings.theme ?? 'dark';
// Logical assignment
user.role ||= 'student';
What to learn next on Toolliyo
- Review this course — practice each lesson in console
- Build a Real-Time Chat App with Node.js — uses async, modules, arrow functions
- Node.js Tutorial — full backend path
- React Tutorial — components + hooks (needs ES6 first)
Course recap checklist
- ✅
let/constand block scope - ✅ Arrow functions and array methods
- ✅ Template literals, destructuring, spread/rest
- ✅ Promises and async/await
- ✅ import / export modules
💡 Tip: In Node.js, save files as .mjs or set "type": "module" in package.json to use import syntax.
⚠️ Common Mistake: Mixing CommonJS require() and ES import in the same file without understanding — pick one module system per project.
👨🏫 Teaching note: Final project: split a small “student grade calculator” into 3 files — math.js, format.js, main.js — using named and default exports.
🎓 Congratulations! You finished Modern JavaScript (ES6+) for Beginners. Your students are ready for Node.js and React.