Web Analytics

ES Modules

Intermediate~20 min

ES modules provide a standardized way to organize and share code using import and export statements.

ES Modules

Output
Click Run to execute your code
Module Types:
  • Named exports: export const x = 1;
  • Default export: export default class {}
  • Import: import { x } from './module';

Export Types

Type Export Import
Named export const x import { x }
Default export default import X
All export * import * as X
Best Practice: Use named exports for utilities, default export for main class/component.

Summary

  • ES modules use import/export
  • Named exports for multiple items
  • Default export for main export
  • Standard module system