SyntaxStudy
Sign Up
JavaScript Intermediate 4 min read

Default Exports

Default Exports

A module can have one default export. The importer can name it anything. Default exports are common for classes and the main export of a module.

Example
// Logger.js
export default class Logger {
  constructor(prefix) {
    this.prefix = prefix;
  }
  log(msg) {
    console.log(`[${this.prefix}] ${msg}`);
  }
}

// app.js
import Logger from "./Logger.js";      // Named anything
import AppLogger from "./Logger.js";   // Same module, different name
const log = new Logger("App");
log.log("Started");
Pro Tip

A module can have both a default export and named exports — combine them when there is one primary export plus helpers.