Skip to content

JavaScript Tutorial Modules

Default Exports

Lesson 168 of 258 2 min read By Deepak Paswan Updated Oct 4, 2026

A module can have one default export: its main thing.

Logger.js
JS
export default class Logger {
  log(message) {
    console.log("[log]", message);
  }
}

Import it without curly braces, and name it however you like:

main.js
JS
import Logger from "./Logger.js";
import Log from "./Logger.js";      // same thing, different local name

new Logger().log("hello");

Other forms

script.js
JS
export default function greet(name) { return "Hi " + name; }   // function
export default 42;                                              // a value
export default { theme: "dark" };                               // an object

Mixing default and named

api.js
JS
export default function request(url) { /* ... */ }
export const BASE_URL = "https://api.example.com";
script.js
JS
import request, { BASE_URL } from "./api.js";

Try it

index.html
HTML
<script type="module">
  const source = "data:text/javascript," + encodeURIComponent(`
    export default function greet(name) { return "Hello, " + name; }
    export const VERSION = 2;
  `);

  const module = await import(source);
  console.log(module.default("Maya")); // → Hello, Maya
  console.log(module.VERSION);         // → 2
</script>

A default export appears as the default property of the module object, which is how dynamic import() exposes it.

Default vs named

Named exportDefault export
Per modulemanyone
Import syntax{ name }any name
Renamingexplicit (as)free, in every file
Editor and search friendlinessbetterworse (names can differ in each file)
Typical useutilities, constants, many functionsa class or component that is the whole point of the file

Which should I use?

Both are valid. Many teams prefer named exports because the name is the same everywhere, it is easy to search for, and typos in imports are caught. Default exports are common for classes and UI components, and some frameworks require them for specific files (for example, page components). Pick one convention for your project, and follow it.

warning
Braces mismatch
import { Logger } from "./Logger.js" fails for a default export, and import Logger from ... fails for a named export. If you see “does not provide an export named”, check which kind you used.