Course contentsShow
← JavaScript
Lesson 1412 of 2,72331. ModulesFree lesson

Importing Default Exports

Learn how to import default exports without curly braces and choose any name for the imported value.

Importing Default Exports

You'll learn how to import default exports using a simpler syntax that lets you choose any name you want.

The Core Idea

When a module exports something as its default export (using export default), you import it without curly braces. Unlike named exports where the name must match exactly, you can give the imported default value any name you choose—it's yours to name!

Syntax and Flexibility

// math.js exports a default
export default function add(a, b) {
  return a + b;
}

// main.js - importing the default
import add from './math.js';
// or any name you prefer:
import myAddFunction from './math.js';
import calculate from './math.js';

All three imports above work identically—they all import the same default function, just under different names in your file.

Why This Matters

Think of a default export like the "main thing" a module offers. When you import it, you're essentially saying "give me the main thing from this module, and I'll call it whatever makes sense in my context."

The named exports you learned earlier require curly braces and exact names. Default exports drop both requirements:

// Importing both default and named exports together
import mainThing, { helper1, helper2 } from './module.js';
// mainThing is the default (no braces, any name)
// helper1 and helper2 are named (braces, exact names)

Key Takeaway: Default exports are imported without curly braces and can be given any name you choose, making them ideal for a module's primary export.